Data Structures With C/C++ Lab
Data Structures With C/C++ Lab
Data Structures With C/C++ Lab
/*PROGRAM 1. Using circular representation for a polynomial, design, develop, and execute a program in C to accept two polynomials, add them, and then print the resulting polynomial.*/ //POLYNOMIAL ADDITION #include <stdio.h> typedef struct { int exp; float coef; }poly; int read_poly(poly p[]) { int i,n; printf("\nEnter the no of terms : "); scanf("%d",&n); for(i=0;i < n;i++) { printf("\nEnter coef : "); scanf("%f",&p[i].coef); printf("\nEnter exp : "); scanf("%d",&p[i].exp); } return(n); } void print_poly(poly p[], int n) { int i; for(i=0;i < n;i++) printf("+%fX^%d ",p[i].coef,p[i].exp); printf("\n"); } int add_poly( poly a[],poly b[],poly c[],int max1,int max2) { int i,j,k; i = j = k = 0; while ( i < max1 && j < max2) { if( a[i].exp > b[j].exp) { c[k] = a[i]; k++; i++; } else if( a[i].exp < b[j].exp) { c[k] = b[j];
BITM
Page 1
BITM
Page 2
BITM
Page 3
BITM
Page 4
BITM
Page 5
BITM
Page 6
BITM
Page 7
BITM
Page 8
BITM
Page 9
BITM
Page 10
BITM
Page 11
BITM
Page 12
BITM
Page 13
BITM
Page 14
BITM
Page 15
BITM
Page 16
BITM
Page 17
BITM
Page 18
BITM
Page 19
BITM
Page 20
BITM
Page 21
BITM
Page 22
BITM
Page 23
BITM
Page 24
BITM
Page 25
BITM
Page 26
BITM
Page 27
BITM
Page 28
BITM
Page 29
BITM
Page 30
BITM
Page 31
BITM
Page 32
BITM
Page 33
BITM
Page 34
BITM
Page 35
BITM
Page 36
BITM
Page 37
enter day: 1
BITM
Page 38
enter day: 1 enter month: 1 enter year: 2012 enter no. of days 365 the new date is: 31/12/2012 press 1 to determine diff=d1-d2 where d1>d2 press 2 to determine d1=d1+ no. of days press 3 to exit enter ur choice 3 *************************************************/
/*PROGRAM 13. Design, develop, and execute a program in C++ to create a class called OCTAL, which has the
BITM
Page 39
BITM
Page 40
/*PROGRAM 14. Design, develop, and execute a program in C++ to create a class called BIN_TREE that represents a
BITM
Page 41
BITM
Page 42
BITM
Page 43
BITM
Page 44
BITM
Page 45