Monday, April 6, 2015

C program for binary search

#include<stdio.h>
#include<conio.h>
void main()
{
 int a[20],n,i,k,mid,s,e,f=0;
 clrscr();
 printf("\n Enter how many number u want:-");
 scanf("%d",&n);
 printf("\n Please enter %d sorted numbers:-",n);
 for(i=0;i<n;i++)
 {
  scanf("%d",&a[i]);
 }
 printf("\n numbers are:-");
 for(i=0;i<n;i++)
 {
  printf("\t%d",a[i]);
 }
 printf("\n\n Enter search key number:-\n");
 scanf("%d",&k);
 s=0;
 e=n-1;
 while(s<=e)
 {
  mid=(s+e)/2;
  if(k==a[mid])
  {
   printf("\n %d number is found on %d position.",k,mid+1);
   f=1;
   break;
  }
  else
  {
   if(k>a[mid])
   {
    s=mid+1;
   }
   else
   {
    e=mid-1;
   }
  }
 }
 if(f==0)
 {
  printf("\n number is not found");
 }
 getch();
}



/* OUTPUT
 Enter how many number u want:-5                                              
                                                                               
 Please enter 5 sorted numbers:-10 11 12 13 14                                
                                                                               
 numbers are:-  10      11      12      13      14                            
                                                                               
 Enter search key number:-                                                    
 12                                                                            
                                                                               
 12 number is found on 3 position.   */

C program for linear searching

#include<stdio.h>
#include<conio.h>
void main()
{
 int a[10],n,i,k,f=0;
 clrscr();
 printf("\n Enter how many number u want:-");
 scanf("%d",&n);
 printf("\n Enter %d numbers:-",n);
 for(i=0;i<n;i++)
 {
  scanf(" %d",&a[i]);
 }
 printf("\n numbers are:-\n");
 for(i=0;i<n;i++)
 {
  printf("\t%d",a[i]);
 }
 printf("\n Enter search key number:-");
 scanf("%d",&k);
 for(i=0;i<n;i++)
 {
  if(k==a[i])
  {
   printf("\n %d number is found on %d position.",k,i+1);
   f=1;
   break;
  }
 }
 if(f==0)
 {
  printf("\n Number is not found");
 }
 getch();
}
/*
 Enter how many number u want:-5                                              
                                                                               
 Enter 5 numbers:-4 6 8 9 14                                                  
                                                                               
 numbers are:-                                                                
        4       6       8       9       14                                    
 Enter search key number:-9                                                    
                                                                               
 9 number is found on 4 position.      */

C program in data structure to make circular linked list

#include<stdio.h>
#include<conio.h>
#include<process.h>
void create();
void display();
void addbeg();
void addlast();
struct node
{
 int info;
 struct node *link;
}*start=NULL;
void main()
{
 int n;
 clrscr();
 while(1)
 {
  printf("\n **menu**\n");
  printf("\n 1. to create list \n 2. to display list");
  printf("\n 3. to add node at beginning of linked list");
  printf("\n 4. to add node at the last of linked list");
  printf("\n 5. exit");
  printf("\n Enter your choice:-");
  scanf("%d",&n);
  switch(n)
  {
   case 1 : create();
   break;
   case 2 : display();
   break;
   case 3 : addbeg();
   break;
   case 4 : addlast();
   break;
   case 5 : exit(0);

  }
 }
 getch();
}

void create()
{
 struct node *temp,*q;
 int x;
 temp=(struct node *)malloc(sizeof(struct node));
 if(temp==NULL)
 {
  printf("\n Insufficient memory");
 }
 else
 {
  printf("\n Enter number:-");
  scanf("%d",&x);
  temp->info=x;
  temp->link=NULL;
  if(start==NULL)
  {
   start=temp;
  }
  else
  {
   q=start;
   while(q->link!=start)
   {
    q=q->link;
   }
   q->link=temp;
  }
  temp->link=start;
 }
}

void display()
{
  struct node *q;
  printf("\n Circular linked list is:-\n\n");
  q=start;
  while(q->link!=start)
  {
   printf("   %d",q->info);
   q=q->link;
  }
  printf("   %d",q->info);
}

void addbeg()
{
 int x;
 struct node *temp,*q;
 temp=(struct node*)malloc(sizeof(struct node));
 if(temp==NULL)
 {
  printf("\n Insufficient memory");
 }
 else
 {
  printf("\n Enter number:-");
  scanf("%d",&x);
  temp->info=x;
  temp->link=NULL;

  q=start;
  while(q->link!=start)
  {
   q=q->link;
  }
  temp->link=start;
  start=temp;
  q->link=start;
 }
}
void addlast()
{
 struct node *temp,*q;
 int x;
 temp=(struct node*)malloc(sizeof(struct node));
 if(temp==NULL)
 {
  printf("\n Insufficient memory");
 }
 else
 {
  printf("\n Enter number:-");
  scanf("%d",&x);
  temp->info=x;
  temp->link=NULL;

  q=start;
  while(q->link!=start)
  {
   q=q->link;
  }
  q->link=temp;
  temp->link=start;
 }
}

C program in data structure to find the intersection between two linked list

#include<stdio.h>
#include<conio.h>
#include<process.h>
#include<stdlib.h>
struct node
{
 int info;
 struct node *link;
}*start1=NULL,*start2=NULL;
void main()
{
 struct node *temp,*q,*p;
 int n,i,x,f=0;
 clrscr();
 printf("\n First linked list");
 printf("\n Enter How many number:-");
 scanf("%d",&n);
 for(i=0;i<n;i++)
 {
  temp=(struct node*)malloc(sizeof(struct node));
  if(temp==NULL)
  {
   printf("\n Insufficient memory");
   getch();
   exit(0);
  }
  printf("\n Enter number:-");
  scanf("%d",&x);
  temp->info=x;
  temp->link=NULL;
  if(start1==NULL)
  {
   start1=temp;
  }
  else
  {
   q=start1;
   while(q->link!=NULL)
   {
     q=q->link;
   }
   q->link=temp;
  }
 }
 printf("\n first list\n");
 q=start1;
 while(q!=NULL)
 {
  printf("\t%d",q->info);
  q=q->link;
 }
 start2=NULL;
 printf("\n Second linked list");
 printf("\n Enter How many number:-");
 scanf("%d",&n);
 for(i=0;i<n;i++)
 {
  temp=(struct node*)malloc(sizeof(struct node));
  if(temp==NULL)
  {
   printf("\n Insufficient memory");
   getch();
   exit(0);
  }
  printf("\n Enter number:-");
  scanf("%d",&x);
  temp->info=x;
  temp->link=NULL;
  if(start2==NULL)
  {
   start2=temp;
  }
  else
  {
   q=start2;
   while(q->link!=NULL)
   {
     q=q->link;
   }
   q->link=temp;
  }
 }
 printf("\n second list\n");
 q=start2;
 while(q!=NULL)
 {
  printf("\t%d",q->info);
  q=q->link;
 }
 printf("\n intersection of two list is:-\n");
 q=start1;
 while(q!=NULL)
 {
  p=start2;
  while(p!=NULL)
  {
   if(q->info==p->info)
   {
    printf("\t%d",q->info);
   }
   p=p->link;
  }
  q=q->link;
 }
 getch();
}

/*   OUTPUT
 First linked list                                                            
 Enter How many number:-5                                                      
                                                                               
 Enter number:-1                                                              
                                                                               
 Enter number:-2                                                              
                                                                               
 Enter number:-3                                                              
                                                                               
 Enter number:-4                                                              
                                                                               
 Enter number:-5                                                              
                                                                               
 first list                                                                    
        1       2       3       4       5                                      
 Second linked list                                                            
 Enter How many number:-4

 Enter number:-1

 Enter number:-2

 Enter number:-5

 Enter number:-6

 second list
1       2       5       6
 intersection of two list is:-
1       2       5            
*/

C program in data structure to reverse the singly linked list

/* Reverse the singly linked list */

#include<stdio.h>
#include<conio.h>
#include<process.h>
struct node
{
 int info;
 struct node *link;
}*start=NULL;
void main()
{
 struct node *temp,*q,*p,*t;
 int n,i,x;
 clrscr();
 printf("\n Enter How many number:-");
 scanf("%d",&n);
 for(i=0;i<n;i++)
 {
  temp=(struct node*)malloc(sizeof(struct node));
  if(temp==NULL)
  {
   printf("\n Insufficient memory");
   getch();
   exit(0);
  }
  printf("\n Enter number:-");
  scanf("%d",&x);
  temp->info=x;
  temp->link=NULL;
  if(start==NULL)
  {
   start=temp;
  }
  else
  {
   q=start;
   while(q->link!=NULL)
   {
     q=q->link;
   }
   q->link=temp;
  }
 }
 t=NULL;
 for(i=0;i<n;i++)
 {
  q=start;
  while(q->link!=t)
  {
   q=q->link;
  }
  t=q;
  printf("\n %d",q->info);
 }
 getch();
}


/* OUTPUT
 Enter How many number:-5                                                      
                                                                               
 Enter number:-1                                                              
                                                                               
 Enter number:-2                                                              

 Enter number:-3                                                              
                                                                               
 Enter number:-4                                                              
                                                                               
 Enter number:-5                                                              
                                                                               
 5                                                                            
 4                                                                            
 3                                                                            
 2
 1              

C program in data structure for concatenate two linked list

#include<stdio.h>
#include<conio.h>
#include<process.h>
#include<string.h>
struct node
{
 int info;
 struct node *link;
}*start1=NULL,*start2;
void main()
{
 struct node *temp,*q;
 int n,i,x;
 clrscr();
 printf("\n First linked list");
 printf("\n Enter How many number:-");
 scanf("%d",&n);
 for(i=0;i<n;i++)
 {
  temp=(struct node*)malloc(sizeof(struct node));
  if(temp==NULL)
  {
   printf("\n Insufficient memory");
   getch();
   exit(0);
  }
  printf("\n Enter number:-");
  scanf("%d",&x);
  temp->info=x;
  temp->link=NULL;
  if(start1==NULL)
  {
   start1=temp;
  }
  else
  {
   q=start1;
   while(q->link!=NULL)
   {
     q=q->link;
   }
   q->link=temp;
  }
 }
 printf("\n first list\n");
 q=start1;
 while(q!=NULL)
 {
  printf("\t%d",q->info);
  q=q->link;
 }
 start2=NULL;
 printf("\n Second linked list");
 printf("\n Enter How many number:-");
 scanf("%d",&n);
 for(i=0;i<n;i++)
 {
  temp=(struct node*)malloc(sizeof(struct node));
  if(temp==NULL)
  {
   printf("\n Insufficient memory");
   getch();
   exit(0);
  }
  printf("\n Enter number:-");
  scanf("%d",&x);
  temp->info=x;
  temp->link=NULL;
  if(start2==NULL)
  {
   start2=temp;
  }
  else
  {
   q=start2;
   while(q->link!=NULL)
   {
     q=q->link;
   }
   q->link=temp;
  }
 }
 printf("\n second list\n");
 q=start2;
 while(q!=NULL)
 {
  printf("\t%d",q->info);
  q=q->link;
 }

 q=start1;
 while(q->link!=NULL)
 {
      //concatenate two linked list
  q=q->link;
 }
 q->link=start2;
 printf("\n After concatenate linked list\n");
 q=start1;
 while(q!=NULL)
 {
  printf("\t%d",q->info);
  q=q->link;
 }
 getch();
}

RDBMS example for project with different quiries

SQL> create table project
  2  (pno number(5) primary key,
  3  pname varchar2(20),
  4  status varchar2(5)
  5  check (status in('c','p','i')));

Table created.
SQL> insert into project values (&pno,'&pname','&status');
SQL> select * from project;

       PNO PNAME                STATU
---------- -------------------- -----
        11 voice_recognition    i
        12 speech_recognition   c
        13 video_recognition    i
        14 steganography        p
        15 cryptography         i

SQL> create table dept
  2  (deptno number(5) primary key,
  3  deptname varchar2(20),
  4  HOD varchar2(20),
  5  location varchar2(20));

Table created.
SQL> insert into dept values (&deptno,'&deptname','&HOD','&location');
SQL> select * from dept;

    DEPTNO DEPTNAME             HOD                  LOCATION
---------- -------------------- -------------------- --------------------
         1 mathematics          vijay                pune
         2 computer             ranjit               pune
         3 chemical             rahul                nasik
         4 civil                ajay                 nagpur
         5 IT                   santosh              nanded

SQL> create table dep_pro
  2  (deptno number(5) references dept,
  3  pno number(5) references project,
  4  primary key (deptno,pno));

Table created.
SQL> insert into dep_pro values (&deptno,&pno);
SQL> select * from dep_pro;

    DEPTNO        PNO
---------- ----------
         1         11
         2         12
         3         13
         4         14
         5         15





Queries:-

1 Find HOD of computer Department located in ‘Pune’.
SQL> select HOD from dept
  2  where deptname='computer' and location='pune';

HOD
--------------------
Ranjit

2 List all projects of mathematics department which are Incomplete.
  SQL>select project.*
from dept,project
where dept.deptno=project.deptno and statu='i'
and deptname='mathmatics';
 
  PNO      PNAME                     STATU
---------- --------------------             -----
  11        voice_recognition             i



3 Display the Project details of Computer Department.
SQL>select project.*
from dept,project
where dept.deptno=project.deptno and deptname='Computer';
       PNO PNAME              
---------- --------------------
        12 speech_recognition  

4 List department wise project along with status.

SQL> select deptname,pname,status from project,dept,dep_pro
  2  where project.pno=dep_pro.pno and
  3  dep_pro.deptno=dept.deptno
  4  group by deptname,pname,status;

DEPTNAME             PNAME                STATU
-------------------- --------------------         -----
IT                   cryptography                    i
chemical             video_recognition       i
civil                steganography                 p
computer             speech_recognition    c
mathematics          voice_recognition    c

Program to develop for cost saving in hotel industry

 To develop a program for cost-saving in a hotel, you can consider the following features: Key Features 1. *Room Management*: Optimize room ...