google.com, pub-4617457846989927, DIRECT, f08c47fec0942fa0 Learn to enjoy every minute of your life.Only I can change my life.

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();
}

अच्छे विचार करे विचार

  पहचान की नुमाईश, जरा कम करें... जहाँ भी "मैं" लिखा है, उसे "हम" करें... हमारी "इच्छाओं" से ज़्यादा "सुन...