Archive for December, 2009

C- Programs for LAB

Sunday, December 13th, 2009

Week 24 1 /* Write C program to implement Simpson method. */ #include #include #include char postfix[80]; float stack[80]; char stack1[80]; int top=-1,top1=-1; float eval(char postfix[], float x1); void infix_postfix(char infix[]); main() { float x0, xn, h, s,e1,e2, e3; char exp[80], arr[80]; int i,n,l=0; clrscr(); printf(“\nEnter an expression: “); gets(exp); puts(“Enter x0, xn and number [...]

C- Programs for LAB

Sunday, December 13th, 2009

Week 23 1 /* Write C program to implement the linear regression algorithm. */ #include #include #include #include float mean(float *a, int n); void deviation(float *a, float mean, int n, float *d, float *S); void main() { float a[20],b[20],dx[20],dy[20]; float sy=0,sx=0,mean_x=0,mean_y=0,sum_xy=0; float corr_coff=0,reg_coff_xy=0, reg_coff_yx=0; char type_coff[7]; int n=0,i=0; clrscr(); printf(“Enter the value of n: “); [...]

C- Programs for LAB

Sunday, December 13th, 2009

Week 22 1 /* Write C program to implement the Lagrange interpolation.*/ #include #include #define MaxN 90 void main() { float arr_x[MaxN+1], arr_y[MaxN+1], numerator, denominator, x, y=0; int i, j, n; clrscr(); printf(“Enter the value of n: \n”); scanf(“%d”, &n); printf(“Enter the values of x and y: \n”); for(i=0; i

C- Programs for LAB

Sunday, December 13th, 2009

Week 21 1 /* Write C program that implement the following sorting methods to sort a given list of integers in ascending order: i) Insertion sort */ #include #include void inst_sort(int []); void main() { int num[5],count; clrscr(); printf(“\nEnter the Five Elements to sort:\n”); for (count=0;count

C- Programs for LAB

Sunday, December 13th, 2009

Week 20 1 /* Write C programs that implement the following sorting methods to sort a given list of integers in ascending order: i) Bubble sort */ #include #define MAX 10 void swapList(int *m,int *n) { int temp; temp = *m; *m = *n; *n = temp; } // Function for Bubble Sort void bub_sort(int [...]

C- Programs for LAB

Sunday, December 13th, 2009

Week 19 1 /* Write C programs that use both recursive and non recursive functions to perform the following searching operations for a Key value in a given list of integers : ii) Binary search*/ #include #define MAX_LEN 10 /* Non-Recursive function*/ void b_search_nonrecursive(int l[],int num,int ele) { int l1,i,j, flag = 0; l1 = [...]

C- Programs for LAB

Sunday, December 13th, 2009

Week 18 1 /* Write a C program that uses functions to perform the following: i) Creating a Binary Tree of integers ii) Traversing the above binary tree in preorder, inorder and postorder. */ #include #include #include struct treenode { int ele; struct treenode *l_child, *r_child; }; struct treenode *insert_node(struct treenode *t,int a); void TraverseInorder(struct [...]

C- Programs for LAB

Sunday, December 13th, 2009

Week 17 1/* Write a C program that uses Stack operations to perform the following: i) Converting infix expression into postfix expression ii) Evaluating the postfix expression */ #include #include int st[100]; int st_top=-1; int cal(char post[]); void in_post(char in[]); void push_item(int it); int pop_item(); int st_ISP(char t); int st_ICP(char t); /*main function*/ void main() [...]

C- Programs for LAB

Sunday, December 13th, 2009

Week 16 1 /* Write C programs that implement Queue (its operations) using i) Arrays */ #include #include #include #define size 10 #define true 1 #define false 0 struct q_arr { int f,r; int num; int a[size]; }; void init(struct q_arr* queue); int e_que(struct q_arr* queue); int f_que(struct q_arr* queue); int add_ele(struct q_arr* queue,int); int [...]

C- Programs for LAB

Sunday, December 13th, 2009

Week 15 1 /* Write C programs that implement stack (its operations) using i) Arrays */ #include #include int st_arr[20]; int t=-1; void push_ele(int ele); int pop_ele(); void display_ele(); void main() { char choice,num1=0,num2=0; while(1) { clrscr(); printf(“======================================”); printf(“\n\t\t MENU “); printf(“\n======================================”); printf(“\n[1] Using Push Function”); printf(“\n[2] Using Pop Function”); printf(“\n[3] Elements present in Stack”); [...]