Archive for the 'Computer Science' Category

C- Programs for LAB

Sunday, December 13th, 2009

Week 14 /* Write a C program that uses functions to perform the following operations on doubly linked list.: i) Creation ii) Insertion iii) Deletion iv) Traversal in both ways */ #include “stdio.h” #include “alloc.h” typedef struct dubll { int data; struct dubll *leftlink,*rightlink; }*DUBLL; DUBLL high,temp_node,low,last,pntr; int flag=0; DUBLL NodeAlloc(); DUBLL Search(int,int); void CreateItem(); [...]

C- Programs for LAB

Sunday, December 13th, 2009

Week 13 1/* Write a program to create a linear linked list interactively and print out the list and the total number of items in the list. */ #include #include #define NULL 0 struct linked_list { int number; struct linked_list *next; }; typedef struct linked_list node; /* node type defined */ main() { node *head; [...]

C- Programs for LAB

Sunday, December 13th, 2009

Week 12 1 /* Write a C program which copies one file to another.*/ #include #include #include void main(int argc, char *argv[]) { FILE *fs,*ft; char ch; clrscr(); if(argc!=3) { puts(“Invalid number of arguments.”); exit(0); } fs = fopen(argv[1],”r”); if(fs==NULL) { puts(“Source file cannot be opened.”); exit(0); } ft = fopen(argv[2],”w”); if (ft==NULL) { puts(“Target [...]

C- Programs for LAB

Sunday, December 13th, 2009

Week 11 1 /* Write a C program that uses functions to perform the following operations: i) Reading a complex number ii) Writing a complex number iii) Addition of two complex numbers iv) Multiplication of two complex numbers (Note: represent complex number using a structure.) */ #include #include void arithmetic(int opern); struct comp { double [...]

C- Programs for LAB

Sunday, December 13th, 2009

Week 10 1 /* 2’s complement of a number is obtained by scanning it from right to left and complementing all the bits after the first appearance of a 1. Thus 2’s complement of 11100 is 00100. Write a C program to find the 2’s complement of a binary number.*/ #include #include void complement (char [...]

C- Programs for LAB

Sunday, December 13th, 2009

Week 9 1 /*Write a C program to read in two numbers, x and n, and then compute the sum of this geometric progression: 1+x+x2+x3+………….+xn For example: if n is 3 and x is 5, then the program computes 1+5+25+125. Print x, n, the sum Perform error checking. For example, the formula does not make [...]

C- Programs for LAB

Sunday, December 13th, 2009

Week 8 1 /* Write a C program to generate Pascal’s triangle. */ #include #include void main() { int bin,p,q,r,x; clrscr(); bin=1; q=0; printf(“Rows you want to input:”); scanf(“%d”,&r); printf(“\nPascal’s Triangle:\n”); while(q0;–p) printf(” “); for(x=0;x

C- Programs for LAB

Sunday, December 13th, 2009

Week 7 1 /* Write a C program to count the lines, words and characters in a given text*/ Program #include main() { char line[81], ctr; int i,c, end = 0, characters = 0, words = 0, lines = 0; printf(“KEY IN THE TEXT.\n”); printf(“GIVE ONE SPACE AFTER EACH WORD.\n”); printf(“WHEN COMPLETED, PRESS ‘RETURN’.\n\n”); while( [...]

C- Programs for LAB

Sunday, December 13th, 2009

Week 6 1 /* Write a C program that uses functions to perform the following operations: To insert a sub-string in to given main string from a given position. */ #include #include #include void main() { char a[10]; char b[10]; char c[10]; int p=0,r=0,i=0; int t=0; int x,g,s,n,o; clrscr(); puts(“Enter First String:”); gets(a); puts(“Enter Second [...]

C- Programs for LAB

Sunday, December 13th, 2009

Week 5 1 /* Write a C program to find both the largest and smallest number in a list of integers*/ main( ) { float largest(float a[ ], int n); float value[4] = {2.5,-4.75,1.2,3.67}; printf(“%f\n”, largest(value,4)); } float largest(float a[], int n) { int i; float max; max = a[0]; for(i = 1; i < [...]