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

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

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