Monday, April 6, 2015

C program in data structure in queue for character DMA Queue

C program in data structure in queue. For character DMA Queue

#include<stdio.h>
#include<conio.h>
#include<process.h>
void insert();
void deletes();
void display();
struct node
{
 char info;
 struct node *link;
}*front=NULL,*rear=NULL;
void main()
{
 int n;
 clrscr();
 while(1)
 {
  printf("\n **menu**\n");
  printf("\n 1. insert \n 2. deletes");
  printf("\n 3. display \n 4. exit");
  printf("\n Enter your choice:- ");
  scanf("%d",&n);
  switch(n)
  {
   case 1 : insert();
   break;
   case 2 : deletes();
   break;
   case 3 : display();
   break;
   case 4 : exit(0);
  }
 }
 getch();
}

void insert()
{
 struct node *temp,*q;
 char x;
 temp=(struct node *)malloc(sizeof(struct node));
 if(temp==NULL)
 {
  printf("\n Insufficient memory");
 }
 else
 {
  printf("\n Enter character:-");
  scanf("%c",&x);
  temp->info=x;
  temp->link=NULL;
  if(rear==NULL&&front==NULL)
  {
   rear=temp;
   front=temp;
  }
  else
  {
   q=rear;
   while(q->link!=NULL)
   {
     q=q->link;
   }
   q->link=temp;
  }
 }
}

void deletes()
{
 struct node *q;
 if(front==NULL&&rear==NULL)
 {
  printf("\n Queue is empty");
 }
 else
 {
   front=rear;
   rear=front->link;
   printf("\n deleted node is %c",front->info);
   free(front);
 }
}

void display()
{
 struct node *q;
 if(front==NULL&&rear==NULL)
 {
  printf("\n Queue is empty");
 }
 else
 {
  front=rear;
  while(front!=NULL)
  {
   printf("\n %c",front->info);
   front=front->link;
  }
 }
}

C program in data structure for polynomial subtraction

#include<stdio.h>
#include<conio.h>
void main()
{
 int a[10],b[10],c[10];
 int n,k,i,p,coeff;
 clrscr();
 for(i=0;i<10;i++)
 {
  a[i]=0;
  b[i]=0;
  c[i]=0;
 }
 printf("\n first polynomial");
 printf("\n enter number of terms=");
 scanf("%d",&n);
 for(i=0;i<n;i++)
 {
  printf("\n enter power & coefficient=");
  scanf("%d%d",&p,&coeff);
  a[p]=coeff;
 }
 printf("\n second polynomial");
 printf("\n enter number of terms=");
 scanf("%d",&k);
 for(i=0;i<k;i++)
 {
  printf("\n enter power & coefficient=");
  scanf("%d%d",&p,&coeff);
  b[p]=coeff;
 }
 for(i=0;i<10;i++)
 {
  c[i]=a[i]-b[i];
 }
 printf("\n polynomial subtraction is=");
 for(i=9;i>=0;i--)
 {
  if(c[i]!=0)
  {
   if(i!=0)
   {
    printf("%dx^%d+",c[i],i);
   }
   else
   {
    printf("%dx^%d",c[i],i);
   }
  }
 }
 getch();
}

C program for multiplication of two polynomial in data structure

#include<stdio.h>
#include<conio.h>
void main()
{
 int a[10],b[10],c[10];
 int i,j,n,k,power,coeff;
 clrscr();
 for(i=0;i<10;i++)
 {
  a[i]=0;
  b[i]=0;
  c[i]=0;
 }
 printf("\n first polynomel");
 printf("\n enter number of terms=");
 scanf("%d",&n);
 for(i=0;i<n;i++)
 {
  printf("\n enter coefficient=");
  scanf("%d",&coeff);
  printf("\n enter power");
  scanf("%d",&power);
  a[power]=coeff;
 }
 printf("\n second polynomel");
 printf("\n enter number of terms=");
 scanf("%d",&k);
 for(i=0;i<k;i++)
 {
  printf("\n enter coefficient=");
  scanf("%d",&coeff);
  printf("\n enter power");
  scanf("%d",&power);
  b[power]=coeff;
 }
 for(i=9;i>=0;i--)
 {
  if(a[i]!=0)
  {
   for(j=9;j>=0;j--)
   {
    if(b[j]!=0)
    {
     c[i+j]=c[i+j]+a[i]*b[j];
    }
   }
  }
 }
 printf("\n our results is=");
 for(i=9;i>=0;i--)
 {
  if(c[i]!=0)
  {
   if(i!=0)
   {
    printf("%dx^%d+",c[i],i);
   }
   else
   {
    printf("%dx^%d",c[i],i);
   }
  }
 }
 getch();
}

C program in data structure for addition of two polynomial

#include<stdio.h>
#include<conio.h>
void show(int p[]);
void main()
{
 int a[10],b[10],c[10];
 int n,k,i,p,coeff;
 clrscr();
 for(i=0;i<10;i++)
 {
  a[i]=0;
  b[i]=0;
  c[i]=0;
 }
 printf("\n First polynomial");
 printf("\n Enter number of terms=");
 scanf("%d",&n);
 for(i=0;i<n;i++)
 {
  printf("\n Enter power & coefficient=");
  scanf("%d%d",&p,&coeff);
  a[p]=coeff;
 }
 printf("\n Second polynomial");
 printf("\n Enter number of terms=");
 scanf("%d",&k);
 for(i=0;i<k;i++)
 {
  printf("\n Enter power & coefficient=");
  scanf("%d%d",&p,&coeff);
  b[p]=coeff;
 }
 printf("\n First polynomial is:-\n\n");
 show(a);
 printf("\n Second polynomial is:-\n\n");
 show(b);
 for(i=0;i<10;i++)
 {
  c[i]=a[i]+b[i];
 }
 printf("\n Addition of two polynomials is=\n\n");
 show(c);
 getch();
}
void show(int p[])
{
  int i;
  for(i=9;i>0;i--)
  {
   if(p[i]!=0)
   {
    printf("%dx^%d+",p[i],i);
   }
  }
  printf("%d",p[i]);
}

C program in data structure for evaluation of polynomial

#include<stdio.h>
#include<conio.h>
#include<math.h>
int eval(int b[],int n,int x);
void main()
{
 int a[10],i,e,n,x;
 clrscr();
 for(i=0;i>10;i++)
 {
  a[i]=0;
 }
 printf("\n Enter number of term:-\n");
 scanf("%d",&n);
 printf("\n Enter co-efficient:-\n");
 for(i=n;i>=0;i--)
 {
  printf("\n Enter co-efficient for A[%d]:-",i);
  scanf("%d",&a[i]);
 }
 printf("\n Polynomial Expression is:-\n");
 for(i=n;i>0;i--)
 {
  if(a[i]!=0)
  {
   printf("%dx^%d+",a[i],i);
  }
 }
 printf("%d",a[i]);
 printf("\n Enter value for x:-\n");
 scanf("%d",&x);
 e=eval(a,n,x);
 printf("\n Evaluation of Polynomial is:-\t%d",e);
 getch();
}
int eval(int b[],int n,int x)
{
 int i,s=0;
 for(i=n;i>=0;i--)
 {
  s=s+b[i]*pow(x,i);
 }
 return(s);
}

C program in data structure of polynomial for implementation of malloc and realloc function

 IMPLEMENTATION OF MALLOC AND REALLOC FUNCTION

#include<stdio.h>
#include<conio.h>
void main()
{
  int s,i,newsize,*p;
  clrscr();
  printf("\n Enter size of an array:-");
  scanf("%d",&s);
  p=(int *)malloc(s*sizeof(int));
  printf("\n Enter the number:-\n");
  for(i=0;i<s;i++)
  {
    scanf("%d",&p[i]);
  }
  printf("\n Entered numbers are:- \n");
  for(i=0;i<s;i++)
  {
    printf(" %d",p[i]);
  }
  printf("\nEnter newsize of an array:-");
  scanf("%d",&newsize);
  p=(int *)realloc(p,newsize);
  printf("\n Enter the numbers for newsize:-\n");
  for(i=s;i<newsize;i++)
  {
    scanf("%d",&p[i]);
  }
  printf("\n All elements of an array is:-\n");
  for(i=0;i<newsize;i++)
  {
    printf(" %d",p[i]);
  }
  getch();
 }

C program in data structure for storage representation of 2-D array

#include<stdio.h>
#include<conio.h>
void main()
{
 int a[10][10],i,j,r,c;
 clrscr();
 printf("\n Enter row and column number:-");
 scanf("%d%d",&r,&c);
 printf("\n Enter %d*%d matrix:-",r,c);
 for(i=0;i<r;i++)
 {
  for(j=0;j<c;j++)
  {
   scanf("%d",&a[i][j]);
  }
 }
 printf("\n storage representation of 2-D array:-");
 for(i=0;i<r;i++)
 {
  for(j=0;j<c;j++)
  {
   printf("\n[%d][%d]= %d",i,j,a[i][j]);
  }
  printf("\n");
 }
 getch();
}



/* OUTPUT
 Enter row and column number:-3 3                                              
                                                                               
 Enter 3*3 matrix:-1 2 3                                                      
                   4 5 6                                                      
                   7 8 9                                                      
                                                                               
 storage representation of 2-D array:-                                        
[0][0]= 1                                                                      
[0][1]= 2                                                                      
[0][2]= 3                                                                      
                                                                               
[1][0]= 4                                                                      
[1][1]= 5                                                                      
[1][2]= 6                                                                      
                                                                               
[2][0]= 7                                                                      
[2][1]= 8                                                                      
[2][2]= 9                                                                      
     */

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 ...