1: /*
2: ==============================================================
3: Name : Doubly Linked List
4: Author : Mujahid, Shivkumar
5: Version :
6: Copyright : Your copyright notice
7: Description : Hello World in C, Ansi-style
8: ===========================================================
9: */
10: #include<stdio.h>
11: #include<stdlib.h>
12: typedef struct dnode
13: {
14: int data;
15: struct dnode *next,*prev;
16: }dnode;
17: dnode *creat();
18: dnode *insert_b(dnode *head,char x);
19: dnode *insert_e(dnode *head,char x);
20: dnode *insert_m(dnode *head,char x);
21: dnode *delete_b(dnode *head);
22: dnode *delete_e(dnode *head);
23: dnode *delete_m(dnode *head);
24: void displayforward(dnode *head);
25: void displaybackward(dnode *head);
26: void main()
27: {
28: int m,n,choice;
29: char x;
30: dnode *head;
31: //clrscr();
32: head=creat();
33: displayforward(head);
34: do
35: {
36: printf("\n_________________________________________________________\n");
37: printf("1. Insert\n2. Delete\n3. Display Forward\n4. Display Backward\n");
38: printf("Enter Your choice: ");
39: scanf("%d",&n);
40: printf("\n");
41: switch(n)
42: { Saturday, 27 September 2014
PL Assignment 11 : Doubly Linked List
PL Assignment 10 : Polynomial
1: /*
2: ==============================================================
3: Name : Polynomial Using CLL
4: Author : Mujahid, Shivkumar
5: Version :
6: Copyright : Your copyright notice
7: Description : Hello World in C, Ansi-style
8: ===========================================================
9: */
10: #include<stdio.h>
11: #include<stdlib.h>
12: struct node
13: {
14: float coef;
15: int expo;
16: struct node *next;
17: };
18: struct node *create(struct node *);
19: struct node *insert_s(struct node *,float,int);
20: struct node *insert(struct node *,float,int);
21: void display(struct node *ptr);
22: void poly_add(struct node *,struct node *);
23: void poly_mult(struct node *,struct node *);
24: int main( )
25: {
26: int op;
27: struct node *start1=NULL,*start2=NULL;
28: do{
29: printf("1.Create\n2.Display\n3.Addition\n4.Multiplication\n5.Exit\nEnter Option : ");
30: scanf("%d",&op);
31: switch(op)
32: {
33: case 1:
34: printf("Enter polynomial 1 :\n");
35: start1=create(start1);
36: printf("Enter polynomial 2 :\n");
37: start2=create(start2);
38: printf("\nPolynomial 1 is : ");
39: display(start1);
40: printf("\nPolynomial 2 is : ");
41: display(start2);
42: break;
43: case 2:
44: printf("\nPolynomial 1 is : ");
45: display(start1);
46: printf("\nPolynomial 2 is : ");
47: display(start2);
48: break;
49: case 3:
50: poly_add(start1, start2);
51: break;
52: case 4:
53: poly_mult(start1, start2);
54: break;
55: case 5:
56: exit(0); PL Assignment 9 : Singly Linked List
1: /*
2: ==============================================================
3: Name : Singly Linked List
4: Author : Mujahid, Shivkumar
5: Version :
6: Copyright : Your copyright notice
7: Description : Hello World in C, Ansi-style
8: ===========================================================
9: */
10: #include<stdio.h>
11: #include<stdlib.h>
12: struct node
13: { int data;
14: struct node *link;
15: };
16: void display(struct node *);
17: void add(struct node **,int);
18: void addn(struct node **,int,int);
19: void delete(struct node**,int);
20: void reverse(struct node *);
21: struct node *rreverse(struct node *head);
22: int main(void)
23: { struct node *p=NULL;
24: int n,n1,n2;
25: do
26: { printf("\n1.Add element\n2.Add at a particular location\n3.delete an element\n4.print the list\n5.print list reverse\n6.print reverse(recursion)\nenter your choice");
27: scanf("%d",&n);
28: switch(n)
29: { case 1:
30: { printf("\nenter element");
31: scanf("%d",&n1);
32: add(&p,n1);
33: }break;
34: case 2:
35: { printf("\nenter element");
36: scanf("%d",&n1);
37: printf("\nat what location do you want to add?");
38: scanf("%d",&n2);
39: addn(&p,n1,n2);
40: }break;
41: case 3:
42: { printf("\nenter element");
43: scanf("%d",&n1);
44: delete(&p,n1);
45: }break; PL Assignment 8 : Sparse Matrix
1: /*
2: ==============================================================
3: Name : Sparse Matrix
4: Author : Mujahid, Shivkumar
5: Version :
6: Copyright : Your copyright notice
7: Description : Hello World in C, Ansi-style
8: ===========================================================
9: */
10: #include<stdio.h>
11: #define MAX 30
12: void creat(int a[10][10],int m,int n);
13: void sparse(int a[10][10],int m,int n,int b[MAX][3]);
14: void print(int b[MAX][3]);
15: void addition(int b1[MAX][3],int b2[MAX][3],int b3[MAX][3]);
16: void transpose(int [][3],int [][3]);
17: void fast_transpose(int [MAX][3],int [MAX][3]);
18: void main()
19: {
20: int a[10][10],b1[MAX][3],b2[MAX][3],b3[MAX][3];
21: int m1,n1,m2,n2,choice,op;
22: printf("Enter First Matrix:");
23: printf("\nEnter number of rows and column:\n");
24: scanf("%d%d",&m1,&n1);
25: creat(a,m1,n1);
26: sparse(a,m1,n1,b1);
27: printf("\n\nEnter Second Matrix:");
28: printf("\nEnter number of rows and column:\n");
29: scanf("%d%d",&m2,&n2);
30: creat(a,m2,n2);
31: sparse(a,m2,n2,b2);
32: printf("\nYour First Sparse Matrix:");
33: print(b1);
34: printf("\n\nYour Second Sparse Matrix:");
35: print(b2);
36: do
37: {
38: printf("\n_______________________________________________________");
39: printf("\nChoose the operation which do you want to perform: ");
40: printf("\n 1.Addition\n 2.Simple Transpose\n 3.Fast Transpose\n");
41: printf("Your choice is: ");
42: scanf("%d",&choice);
43: switch(choice)
44: {
45: case 1:
46: if(m1==m2 && n1==n2)
47: {
48: printf("\nAddition of Sparse Matrix:\n");
49: addition(b1,b2,b3);
50: print(b3);
51: } PL Assignment 7 : Quick sort recursively
1: /*
2: ==============================================================
3: Name : Mobile Information
4: Author : Shivkumar, Mujahid
5: Version :
6: Copyright : Your copyright notice
7: Description : Hello World in C, Ansi-style
8: ===========================================================
9: */
10: #include<stdio.h>
11: #include<string.h>
12: typedef struct mobile
13: {
14: char mobile_no[11];
15: int bal;
16: char name[20];
17: }mobile;
18: void creat(mobile st[],int n);
19: void insert(mobile st[],int position,int n);
20: void del(mobile st[],int position,int n);
21: int search(mobile st[],char mobile_no[],int n);
22: void print(mobile st[],int n);
23: void sort_bal(mobile st[],int n);
24: void sort_name(mobile st[],int n);
25: void modify(mobile st[],int n);
26: /*---- Main Function ----*/
27: void main()
28: {
29: mobile st[20];
30: int n,position,choice,count;
31: char mobile_no[15];
32: printf("\nEnter number of mobile: ");
33: scanf("%d",&n);
34: creat(st,n);
35: print(st,n);
36: do
37: {
38: printf("--------------------------------------------------------------");
39: printf("\nChoose the operation which do you want to perform: ");
40: printf("\n 1.Insert\n 2.Print\n 3.Delete\n 4.Search\n 5.Sort By bal(Descending Order)\n ");
41: printf("6.Sort By Name(Ascending Order)\n 7.Modify\n");
42: printf("Your choice is: ");
43: scanf("%d",&choice);
44: switch(choice)
45: {
46: case 1: PL Assignment 6 : Searching and Sorting of students information
1: /*
2: ==============================================================
3: Name : Student Information
4: Author : Mujahid, Shivkumar
5: Version :
6: Copyright : Your copyright notice
7: Description : Hello World in C, Ansi-style
8: ===========================================================
9: */
10: #include<stdlib.h>
11: #include<string.h>
12: #include<stdio.h>
13: #include<ctype.h>
14: #include<math.h>
15: typedef struct student
16: { char name[30];
17: int roll_no;
18: long long int mob;
19: char address[100];
20: }stud;
21: void ip(stud *,int);
22: void sort_asc(stud *,int);
23: void sort_ascn(stud *,int);
24: void sort_des(stud *,int);
25: void print(stud *,int);
26: void swap(stud *,stud *);
27: void search(stud *,int,int);
28: int main(void)
29: { int n,i,j;
30: printf("How many records will you enter?");
31: scanf("%d",&n);
32: if(n<=0)
33: { printf("\nenter valid numbers!");
34: exit(0);
35: }
36: stud *s=(stud *)malloc(n*sizeof(stud)),*s1,*s2;
37: ip(s,n);
38: do
39: { printf("\n1.Sort in ascending order\n2.Sort in descending order\n3.Search\nEnter your choice");
40: scanf("%d",&j);
41: switch(j)
42: { case 1:
43: { s1=s;
44: sort_asc(s1,n);
45: //print(s1,n);
46: }break; PL Assignment 5 : File operations using command line argument
1: /*
2: ==============================================================
3: Name : File Operations
4: Author : Mujahid, Shivkumar
5: Version :
6: Copyright : Your copyright notice
7: Description : Hello World in C, Ansi-style
8: ===========================================================
9: */
10: #include<stdio.h>
11: #include<stdlib.h>
12: void filecpy(char *,char *);
13: int main(int argc, char *argv[])
14: {
15: if(argc!=3)
16: { printf("invalid number of arguments");
17: exit(0);
18: }
19: filecpy(argv[1],argv[2]);
20: return 0;
21: }
22: void filecpy(char *p,char *q)
23: { FILE *f1,*f2;
24: char c[200];
25: f1=fopen(p,"r");
26: f2=fopen(q,"w");
27: if(f1==NULL)
28: { printf("no such file");
29: exit(0);
30: }
31: while(fgets(c,200,f1)!=NULL)
32: fputs(c,f2);
33: fclose(f1);
34: fclose(f2);
35: } PL Assignment 4 : Array of structure
1: /*
2: ============================================================================
3: Name : Array Of Structure
4: Author : Mujahid, Shivkumar
5: Version :
6: Copyright : Your copyright notice
7: Description : Hello World in C, Ansi-style
8: ============================================================================
9: */
10: #include <stdio.h>
11: #include <stdlib.h>
12: #define max 10
13: typedef struct
14: {
15: char name[30];
16: int rollno;
17: char mobno[10];
18: }student;
19: int getdata(student *s)
20: {
21: int i,n;
22: printf("Enter the number of students : \n");
23: scanf("%d",&n);
24: for(i=0;i<n;i++)
25: {
26: printf("Enter name : \n");
27: scanf("%s",&(s+i)->name);
28: (s+i)->rollno=valid_roll(s,i);
29: valid_mob(s,i);
30: }
31: return i;
32: }
33: int valid_roll(student *s,int n)
34: {
35: int i,roll;
36: printf("Enter roll number\n");
37: scanf("%d",&roll);
38: if(roll<0)
39: { PL Assignment 3 : String Operations
1: /*
2: ============================================================================
3: Name : String Operations
4: Authors : Shivkumar, Mujahid
5: Version :
6: Copyright : Your copyright notice
7: Description : Hello World in C, Ansi-style
8: ============================================================================
9: */
10: #include <stdio.h>
11: #define max 10
12: int length(char*);
13: void copy(char*,char*);
14: int palindrome(char*);
15: void reverse(char*);
16: int compare(char*,char*);
17: void concat(char*,char*);
18: void substr(char*,char*);
19: int main()
20: {
21: char s1[max],s2[max];
22: char *str1,*str2;
23: int ch,len,comp,temp,i;
24: do
25: {
26: printf("\nMENU\n");
27: printf("1. Length of String\n");
28: printf("2. Copy\n");
29: printf("3. Palindrome\n");
30: printf("4. Reverse\n");
31: printf("5. Compare\n");
32: printf("6. Concatenate\n");
33: printf("7. Substring\n");
34: printf("0. Exit\n");
35: printf("\nEnter choice :\n");
36: scanf("%d",&ch);
37: printf("Enter String :\n");
38: scanf("%s",&s1);
39: str1=s1; //Assigns value to str1 of s1;
40: printf("Entered String : %s",s1);
41: switch(ch)
42: {
43: case 1: len=length(str1);
44: printf("\nLength of String : %d\n",len);
45: break;
46: case 2: printf("\nCopy :\n");
47: copy(str2,str1);
48: printf("\nCopied String : %s",str2);
49: break;
50: case 3: temp=palindrome(str1);
51: if(temp==1)
52: printf("\n%s is not a Palindrome",str1);
53: else
54: printf("\n%s is a Palindrome",str1);
55: break;
56: case 4: reverse(str1);
57: printf("\nReversed String : %s",str1);
58: reverse(str1);//For getting the original string back
59: break;
60: case 5: printf("\nEnter second string :\n");
61: scanf("%s",&s2);
62: str2=s2; //Assigning Char value to Pointer
63: printf("\nEntered String : %s",str2);
64: comp=compare(str1,str2);
65: if(comp==0) PL Assignment 2 : Matrix Operations
1: /*
2: ============================================================================
3: Name : Matrix Operations
4: Authors : Shivkumar, Mujahid
5: Version :
6: Copyright : Your copyright notice
7: Description : Hello World in C, Ansi-style
8: ============================================================================
9: */
10: int *input(int **mat,int *row,int *col)
11: {
12: int i,j;
13: printf("\nEnter Number of Rows and columns :\n");
14: scanf("%d%d",row,col);
15: mat=malloc(*row * sizeof(int*));
16: for(i=0;i<*row;i++)
17: {
18: mat[i]=malloc(*col * sizeof(int*)); //While using malloc use m[i] instead of *(m+i)
19: if(mat[i]==0)//While using malloc use m[i] instead of *(m+i)
20: {
21: printf("\nMemory can not be alloted.\n");
22: return 0;
23: }
24: }
25: printf("\nEnter Elements :\n");
26: for(i=0;i<*row;i++)
27: for(j=0;j<*col;j++)
28: {
29: scanf("%d",(*(mat+i)+j));
30: // printf("%d\n",*(*(mat+i)+j));
31: }
32: return(mat);
33: }
34: void display(int **mat,int row,int col)
35: {
36: int i,j;
37: printf("\nMatrix :");
38: printf("\nRow : %d Col : %d",row,col);
39: for(i=0;i<row;i++)
40: {
41: printf("\n");
42: for(j=0;j<col;j++)
43: printf(" %d ",*(*(mat+i)+j));
44: } PL Assignment 1 : Set Operations Using Array
1: /*
2: * Title : Set Operations Using Array
3: *
4: * Author : Shivkumar, Mujahid
5: *
6: */
7: #include<stdio.h>
8: int uni(int a[10],int b[10],int k,int l);
9: int inter(int a[10],int b[10],int k,int l);
10: int diff(int a[10],int b[10],int k,int l);
11: int symdiff(int a[10],int b[10],int k,int l);
12: /*----- Main Function -----*/
13: int main()
14: {
15: int a[10],b[10],i,j,k,l,choice,count;
16: printf("Enter number of elements in set A: ",k);
17: scanf("%d",&k);
18: printf("Enter elements in set A: ");
19: printf("\n");
20: for(i=0;i<k;i++)
21: scanf("%d",&a[i]);
22: printf("\nEnter number of elements in set B: ",l);
23: scanf("%d",&l);
24: printf("Enter elements in first set B:");
25: printf("\n");
26: for(i=0;i<l;i++)
27: scanf("%d",&b[i]);
28: do
29: {
30: printf("\n---------------------------------------------------------------");
31: printf("\nChoose the operation which you want to perform:");
32: printf("\n 1.Union\n 2.Intersection\n 3.Difference\n 4.Symmetric difference\n 5.Exit",choice);
33: printf("\nYour choice is: ");
34: scanf("%d",&choice);
35: printf("\n\n");
36: switch(choice)
Subscribe to:
Posts (Atom)