Professional Documents
Culture Documents
by:
Prof. A.Syed Mustafa
1. #include<stdio.h>
2. #include<conio.h>
3. int a[100],n,i;
4.
5. /*create array with n elements*/
6. void createarray( )
7. {
8. printf("Enter the total no. of elements\n");
9. scanf("%d",&n);
10. printf("Enter the Elements\n");
11. for(i=0;i<n;i++)
12. scanf("%d",&a[i]);
13. }
14.
15. /* display all array elements*/
16. void displayarray( )
17. {
18. printf("The Elements in the array are:\n");
19. for(i=0;i<n;i++)
20. printf("%d\t",a[i]);
21. }
22.
23. /*insert the element at given position*/
24. void insertelement( )
25. {
26. int pos,elem;
27. printf("Enter the position of the element to be inserted\n");
28. scanf("%d",&pos);
29. if(pos<1 || pos>n)
30. printf("Invalid Positon\n");
31. else
32. {
33. printf("enter the element to be inserted\n");
34. scanf("%d",&elem);
35. for (i = n; i >= pos; i--) /* shift elements left to right*/
36. a[i]=a[i-1];
37. a[i]=elem;
38. n++;/* total no. of elements in array increased by 1*/
39. }
40. }
41.
1. #include<stdio.h>
2. #include<conio.h>
3.
4.
5. /*reading input string*/
6. void readstr(char s[ ])
7. {
8. int i=-1;
9. do
10. {
11. s[++i]=getchar( );
12. }while(s[i]!='\n');
13. s[i]=0;
14. }/*end readstr*/
15.
16. /*shifting right or left-shrinking or expanding */
17. void shift(char str[], int s, int slen, int rlen)
18. {
19. int i,len, nocs;
20. for(i=0;str[i]!=0;i++);
21. len=i;
22.
23.
24. if (rlen>slen)
25. {
26. /*if replacement string is having more characters than searching string */
27. nocs = rlen - slen; /* no. of characters to be shifted*/
28. for (i = len; i >= s + slen; i--) /* shift left to right */
29. str[i+nocs]=str[i];
30. }/*end if*/
31. else
32. {
33. /*if replacement string is having less characters than searching string */
34. nocs=slen-rlen; /* no. of characters to be shifted*/
35. for(i=s+rlen;i<=len-nocs;i++)/* shift right to left */
36. str[i]=str[i+nocs];
37. }/*end else*/
38.
39. }/*end shift*/
OUTPUT:
1. #include<stdio.h>
2. #include<conio.h>
3. int tos=-1,max,a[100];
4.
5. /*insert the element into the stack*/
6. void push(int elem)
7. {
8. if(tos = = max-1)
9. printf("Stack Overflow\n");
10. else
11. a[++tos]=elem;
12. } /* end push*/
13.
14. /* remove the element from the stack*/
15. int pop( )
16. {
17. return(a[tos--]);
18. } /* end pop*/
19.
20.
21. /*display the content of the stack*/
22. void display( )
23. {
24. int i;
25. if(tos<0)
26. printf("Stack is empty\n");
27. else
28. for(i=tos;i>=0;i--)
29. printf("%d\t",a[i]);
30. }/*end display*/
31.
32. /*find the given no. is palindrome or not*/
33. void palindrome( )
34. {
35. int n,no,d,p=1;
36. tos=-1;
37. max = 5; /* till 5 digit no. 32767 or 65536 - max int value, size of stack-5 */
38. printf("enter the number to check palindrome\n");
39. scanf("%d",&n);
40. no=n;
OUTPUT:
OUTPUT:
5. Design, Develop and Implement a Program in C for the following Stack Applications:
a. Evaluation of Suffix expression with single digit operands and operators: +, -, *, /, %, ^
b. Solving Tower of Hanoi problem with n disks.
OUTPUT:
1. #include<stdio.h>
2. #include<conio.h>
3.
4. /* C recursive function to solve tower of hanoi */
5. void TowerOfHanoi(int n, char source, char dest, char inter)
6. {
7. if (n == 1)
8. printf("\n Move disk 1 from rod %c to rod %c", source, dest);
9. else
10. {
11. /* from source to intermediate through destination*/
12. TowerOfHanoi(n - 1, source, inter, dest);
13. printf("\n Move disk %d from rod %c to rod %c", n, source, dest);
14. /* from intermediate to destination through source */
15. TowerOfHanoi(n - 1,inter, dest, source);
16. }/*end if*/
17. }/*end TowerofHanoi*/
18.
19. void main( )
20. {
21. int n;
22. clrscr( );
23. printf("Enter total no of disks\n");
24. scanf("%d",&n);
25. TowerOfHanoi(n, 'A', 'C', 'B'); // A, B and C are names of rods
26. getch( );
27. }/*end main*/
OUTPUT:
1. #include<stdio.h>
2. #include<conio.h>
3. int max,count=0,f=0,r = -1;
4. char a[100],elem;
5.
6. /*insert element into circular queue*/
7. void InsertQ( )
8. {
9. if(count==max)
10. printf("Queue is Full\n");
11. else
12. {
13. printf("Enter the element to be inserted\n");
14. fflush(stdin);
15. elem=getchar();
16. r = (r + 1) % max; /* if rear end reached the max size of Queue, go to begining*/
17. a[r]=elem;
18. count++;/* count of element in the queue incremented*/
19. }/*end else*/
20. } /* end insert*/
21.
22. /*Remove the element from circular Queue*/
23. void DeleteQ( )
24. {
25. if(count = = 0)
26. printf("Queue is Empty\n");
27. else
28. {
29. elem=a[f];
30. f=(f+1)%max;/* if front end reached the max size of Queue, go to begining*/
31. printf("Element deleted is %c\n",elem);
32. count--;/* count of element in the queue decremented*/
33. }/*end else*/
34. } /*end Delete*/
35.
36. /* Display the content of circular queue*/
37. void DisplayQ( )
38. {
39. int i;
40. if(count = = 0)
41. printf("Queue is Empty\n");
OUTPUT:
1. #include<stdio.h>
2. #include<conio.h>
3. #include<alloc.h>
4.
5. /*create structure to store student detail*/
6. struct student
7. {
8. char usn[12];
9. char name[25];
10. char branch[25];
11. int sem;
12. char phone_no[12];
13. struct student *link;
14. };
15.
16. typedef struct student STUD;
17.
18. /*to get student details from user*/
19. STUD *read_data()
20. {
21.
22. STUD *temp;
23.
24. temp = (STUD *)malloc(sizeof(STUD)); /*create a node which stores student's details*/
25. printf("Enter the Students Details:\n");
26. printf("Enter USN\n");
27. scanf("%s",temp->usn);
28. printf("Enter Name\n");
29. scanf("%s",temp->name);
30. printf("Enter Branch \n");
31. scanf("%s",temp->branch);
32. printf("Enter Semester\n");
33. scanf("%d",&temp->sem);
34. printf("Enter Phone Number\n");
35. scanf("%s",temp->phone_no);
36.
37. temp->link = NULL;/*link part of node is assigned with null value*/
38.
39. return temp;
40. }/*end of read_data*/
OUTPUT:
1. #include<stdio.h>
2. #include<conio.h>
3. #include<alloc.h>
4.
5. /*create structure to store Employee detail*/
6. struct emp
7. {
8. char ssn[12];
9. char name[50];
10. char dept[50];
11. char design[25];
12. long salary;
13. char phone_no[12];
14. struct node *llink;
15. struct node *rlink;
16. };
17.
18.
19. typedef struct emp EMP;
20.
21. /*function prototypes*/
22. EMP *read_data( );
23. EMP* insert_End(EMP* first);
24. EMP * CreateDLL(EMP *first);
25. void DisplayDLL(EMP* first);
26. EMP* Delete_End(EMP* first);
27. EMP* InsertDeleteEnd(EMP* first);
28. EMP* Dequeue(EMP* first);
29.
30. /*to get Employee details from user*/
31. EMP *read_data( )
32. {
33. /*create a node which stores employee's details*/
34. EMP *temp=(EMP*)malloc(sizeof(EMP));
35. printf("Enter the Employees Details:\n");
36. printf("Enter SSN\n");
37. scanf("%s",temp->ssn);
38. printf("Enter Name\n");
39. scanf("%s",temp->name);
135. /*to insert and remove the node from the end of list*/
136. EMP* InsertDeleteEnd(EMP* first)
137. {
138. int ch;
139. while(1)
140. {
141. printf("\n1.Insert at End\n2.Delete at End\n3.Display\n4.Main Menu");
142. printf("Enter the Choice\n");
143. scanf("%d",&ch);
144. switch(ch)
145. {
146. case 1: first=insert_End(first);
147. break;
148. case 2: first=Delete_End(first);
149. break;
150. case 3: DisplayDLL(first);
151. break;
152. case 4: return(first);
153.
154. default: printf("Invalid Choice\n");
155. } /* end switch*/
156. }/* end while*/
157. }/*end InsertDeleteEnd*/
158.
159.
160. /*to insert the node in the begining of list*/
161. EMP *insert_front(EMP *first)
162. {
163. EMP *temp;
164. temp=read_data();/* get new node which has employee's detail*/
165. if(first!=0)
166. {
167. temp->rlink=first;/*assign the previous first node as right link to the new node*/
168. first->llink=temp;/*assign the previous first node's left link as new node*/
169. }
170. return temp;/*return the new-[next node] as first node*/
171. }/*end Insert_front*/
172.
173.
174. /*to delete the node from the begining of list*/
175. EMP* Delete_front(EMP* first)
176. {
177. EMP* cur=first;/* assign first node as current node */
178. if(first==0)/*if no first node*/
179. printf("List is Empty\n");
180. else
181. { /* if there are nodes*/
182. printf("\nDeleted Employee Details are:\n");
183. printf("SSN\tNAME\tDEPARTMENT\t");
OUTPUT:
9. Design, Develop and Implement a Program in C for the following operations on Singly Circular
Linked List (SCLL) with header nodes
a. Represent and Evaluate a Polynomial P(x,y,z) = 6x2y2z-4yz5+3x3yz+2xy5z-2xyz3
b. Find the sum of two polynomials POLY1(x,y,z) and POLY2(x,y,z) and store the result in
POLYSUM(x,y,z)
Support the program with appropriate functions for each of the above operations.
1. #include<stdio.h>
2. #include<conio.h>
3. #include<alloc.h>
4. #include<math.h>
5.
6. typedef struct
7. {
8. int coef, xexp, yexp, zexp;
9. struct poly *link;
10. }POLY;
11.
12. /*insert the polinomial term-node at the end of the list*/
13. void attach(POLY *poly1,int coef,int xexp,int yexp,int zexp)
14. {
15.
16. POLY *nnode, *cur;
17. nnode = (POLY*)malloc(sizeof(POLY));/*create new node for each polynomial term*/
18. nnode->coef = coef;/*assign coefficient value in the node*/
19. nnode->xexp = xexp;/*assign exponent value of x in the node*/
20. nnode->yexp = yexp;/*assign exponent value of y in the node*/
21. nnode->zexp = zexp;/*assign exponent value of z in the node*/
22.
23. cur = poly1->link;/*assign first node pointed by header node's link to current pointer*/
24. /*traverse as long as the node is not header node-till reaching last node*/
25. while (cur->link != poly1)
26. cur = cur->link; /*assign next node as current node*/
27.
28. cur->link = nnode;/*assign new node to link of last[current] node*/
29. nnode->link = poly1;/*link new node to header node-poly1*/
30.
31. }/* end of attach-insert at end */
32.
33.
34. /*creating a polinomial with many terms*/
35. void createpoly(POLY *poly1)
36. {
37. int n, i, coef, xexp, yexp, zexp;
38.
39. printf("Enter no of terms\n");
40. scanf("%d", &n);
41. printf("enter the details of the ploynomial\n");
OUTPUT:
10. Design, Develop and Implement a menu driven Program in C for the following operations on
Binary Search Tree (BST) of Integers:
a. Create a BST of N Integers: 6, 9, 5, 2, 8, 15, 24, 14, 7, 8, 5, 2
b. Traverse the BST in Inorder, Preorder and Post Order
c. Search the BST for a given element (KEY) and report the appropriate message
d. Exit
1. #include<stdio.h>
2. #include<conio.h>
3. #include<alloc.h>
4.
5.
6. struct BSTree
7. {
8. int data;
9. struct BStree *rlink, *llink;
10. };
11.
12.
13. typedef struct BSTree BST;
14.
15. /*function prototypes*/
16. BST* read_data( );
17. void insertBST(BST* root, BST* temp);
18. BST* CreateBST(BST *root);
19. void DisplayBST(BST* root);
20. int searchBST(BST *root, int key);
21.
22. /*read data for each node*/
23. BST *read_data()
24. {
25. BST *temp = (BST*)malloc(sizeof(BST));/*create a new node for every value*/
26. printf("Enter the number:\n");
27. scanf("%d",&temp->data);
28. temp->rlink = temp->llink = 0;/*assign null value to rlink and llink of node*/
29. return temp;/*return the new node's address*/
30. }/*end read_data*/
31.
32. /*inset into Binary search tree*/
33. void insertBST(BST* root,BST* temp)
34. {
35. if (temp->data <= root->data)/*if current data is less than root data*/
36. {
37. if (root->llink == 0)/*if left link of root is null*/
38. root->llink = temp;/*assign new node[temp] to the left link of root*/
39. else
40. insertBST(root->llink, temp);
41. /*call the same function again by traversing towards left side*/
42. }
11. Design, Develop and Implement a Program in C for the following operations on Graph(G) of
Cities
a. Create a Graph of N cities using Adjacency Matrix.
b. Print all the nodes reachable from a given starting node in a digraph using DFS/BFS method
12. Given a File of N employee records with a set K of Keys(4-digit) which uniquely determine the
records in file F. Assume that file F is maintained in memory by a Hash Table(HT) of m memory
locations with L as the set of memory addresses (2-digit) of locations in HT. Let the keys in K
and addresses in L are Integers.
Design and develop a Program in C that uses Hash function H: K ®L as H(K)=K mod m
(remainder method), and implement hashing technique to map a given key K to the address
space L. Resolve the collision (if any) using linear probing.
1. #include <stdio.h>
2. #define msize 10 /*no of memory locations / Hash Table Size*/
3. int ht[msize];
4.
5. /*hash function returns the last digit of key*/
6. int hash(int key)
7. {
8. return key%msize; /*return remainder-last digit*/
9. }/*end hash*/
10.
11. void linear_probe(int hk,int key)
12. {
13. int i,flag=0;
14. for (i=hk+1;i<msize;i++)
15. /*check the hash table after the key index-2nd half of hash table*/
16. {
17. if (ht[i]==999)/*in hash table,free index is found-ie 999*/
18. {
19. ht[i]=key;/*assign the key value to hash table*/
20. flag=1;/*set flag as 1*/
21. break; /*teminate the for loop*/
22. }/*end if*/
23. }/*end for*/
24.
25. for(i=0;i<hk&&flag==0;i++)
26. /*check the hash table before the key index-1st half of hashtable*/
27. {
28. if (ht[i]==999)/*in hash table table,free index is found-ie 999*/
29. {
30. ht[i]=key;/*assign the key value to hash table*/
31. flag=1;/*set flag as 1*/
32. break;/*teminate the for loop*/
33. }/*end if*/
34. }/*end for*/
35. if (flag==0) /*if no index is free in hash table*/
36. printf("HASH Table is Full!!!\n");
37. }/*end linear_probe*/
OUTPUT:
VISION To empower the students through wholesome education & enable
the students to develope into highly qualified and trained
professionals with ethics and emerge as responsible citizens to
build a vibrant nation.
To provide educational opportunities to the deprived and weaker
section of the society to uplift their socioeconomic status.
To train skilled and ethical professionals with the ability to plan,
design, develop, organize and manage modern and traditional
information systems with the knowledge of information
technologies, services and organizations globally.
MISSION
To impart high quality engineering education in the field of
Information Science and Technology with strong theoretical and
extensive practical training methodologies through innovation
and research to make worldclass Engineers.