Issuu on Google+

Assignment – DFS Name: Priyank Patel S.Y.BCA - 45

Array 1. Execute a program for single dimension array which perform following operation: a. Insert b. Delete c. Traverse d. Exit è #include<conio.h> int n=10; int a[10]; main() { int o; clrscr(); printf("1. Insert \n"); printf("2. Delete \n"); printf("3. Traverse \n"); printf("4. Exit\n"); printf("Choose the option ....: "); scanf("%d",&o); switch(o) { case 1: ins(); main(); break; case 2: del(); main(); break; case 3: trav(); main(); break; case 4: exit(0); default: printf("pls choose menu option only...."); } ins() { int pos,val,i; printf("Insert:\n"); printf("Enter a position : "); scanf("%d",&pos); printf("Enter a value : "); scanf("%d",&val); for(i=n-1;i>pos;i--) { a[i+1]=a[i]; a[pos]=val; n++; getch(); }

}

del()

Page 1 of 50

break; }


Assignment â&#x20AC;&#x201C; DFS Name: Priyank Patel S.Y.BCA - 45 { int val,i; printf("Delete:\n"); printf("Enter A Value :"); scanf("%d",&val); for(i=0;i<n;i++) {if(a[i]==val) while(i<n) {a[i]=a[i+1]; i++; } n--; getch(); } trav() { int i; printf("Traverse :\n"); for(i=0;i<n;i++) { printf("\n %d",a[i]); getch(); }

}

}

Page 2 of 50


Assignment â&#x20AC;&#x201C; DFS Name: Priyank Patel S.Y.BCA - 45 2. Write a menu base 2D program following operation: a. Display individual (Two) Matrix b. Matrix addition c. Matrix multiplication d. Exit è #include<conio.h> int m1[3][3]={{1,2,3},{4,5,6},{7,8,9}}; int m2[3][3]={{1,2,3},{4,5,6},{7,8,9}}; int m3[3][3]; int i,j; main() { int o; clrscr(); printf("1. Display\n"); printf("2. Matrix Addition\n"); printf("3. Multiplication \n"); printf("4. Exit\n"); printf("option Select.... :"); scanf("%d",&o); switch(o) {case 1: disp(); main(); break; case 2: add(); main(); break; case 3: multi(); main(); break; case 4: exit(0); break; default:printf("pls choose the option value....");main();break; } disp() { printf("\n\nDisplay Matrix.......\n"); printf("\n\nMatrix 1 \t Matrix 2\n"); for(i=0;i<3;i++) { for(j=0;j<3;j++) { printf(" %d ",m1[i][j]); } printf("\t"); for(j=0;j<3;j++) { printf(" %d ",m2[i][j]); } printf("\n"); } getch(); }

Page 3 of 50

}


Assignment â&#x20AC;&#x201C; DFS Name: Priyank Patel S.Y.BCA - 45 add() { printf("\n\nAddition .......\n"); for(i=0;i<3;i++) { for(j=0;j<3;j++) { printf("%d\t",m1[i][j]+m2[i][j]); } printf("\n"); } getch(); } multi() { int k; printf("\n\nMultiplication......\n"); for(i=0;i<3;i++) { for(j=0;j<3;j++) { for(k=0;k<3;k++) { m3[i][j]+=m1[i][k]*m2[k][j]; } printf("%d \t",m3[i][j]); } printf("\n"); } getch(); }

Page 4 of 50


Assignment â&#x20AC;&#x201C; DFS Name: Priyank Patel S.Y.BCA - 45

3. Write a menu base 2D program which perform following operation: a. Display individual (two) matrix b. Transpose of the matrix c. Matrix Subtraction d. Matrix Multiplication e. Exit è #include<conio.h> int m1[3][3]={{1,2,3},{4,5,6},{7,8,9}}; int m2[3][3]={{1,2,3},{4,5,6},{7,8,9}}; int m3[3][3]; int i,j,k,o; main() { clrscr(); printf("1. Display matrix \n"); printf("2. Transpose of matrix \n"); printf("3. Matrix Subtraction \n"); printf("4. Matrix Multiplication \n"); printf("5. Exit\n"); printf("Choose one option ..... :"); scanf("%d",&o); switch(o) {case 1: disp(); main(); break; case 2: trans(); main(); break; case 3: sub(); main(); break; case 4: mul(); main(); break; case 5: exit(0); main(); break; default : printf("choose one option in menu....!"); } getch(); }

main();break;

disp() { printf("\n\nDisplay.......\n"); printf("\n Matrix 1 \t Matrix 2\n"); for(i=0;i<3;i++) { for(j=0;j<3;j++) { printf(" %d ",m1[i][j]); } printf("\t"); for(j=0;j<3;j++)

Page 5 of 50


Assignment â&#x20AC;&#x201C; DFS Name: Priyank Patel S.Y.BCA - 45 {

printf(" %d ",m2[i][j]); }

printf("\n"); } getch(); } trans() { printf("\n\nTranspose.......\n"); for(i=0;i<3;i++) { for(j=0;j<3;j++) { printf(" %d ",m1[j][i]); } printf("\n"); } getch(); } sub() { printf("\n\nSubtraction.....\n"); for(i=0;i<3;i++) { for(j=0;j<3;j++) { printf(" %d ",m1[i][j]-m1[i][j]); } printf("\n"); } getch(); } mul() { printf("\n\nMultiplication....\n"); for(i=0;i<3;i++) { for(j=0;j<3;j++) { for(k=0;k<3;k++) { m3[i][j]+=m1[i][k]*m2[k][j]; printf(" %d ",m3[i][j]); } printf("\n"); } getch(); }

}

Page 6 of 50


Assignment â&#x20AC;&#x201C; DFS Name: Priyank Patel S.Y.BCA - 45

Sorting and Searching 1. To execute program for merge sort method. è #include<conio.h> int i,j,k,a[5],b[5],c[10],tmp,t; main() { clrscr(); printf("enter first array: \n"); for(i=0;i<5;i++) { printf("pls enter a value of %d",i+1); scanf("%d",&a[i]); } printf("enter 2nd array: \n"); for(i=0;i<5;i++) { printf("pls enter a value of %d",i+1); scanf("%d",&b[i]); } for(i=0;i<4;i++) { for(j=i+1;j<5;j++) { if(a[i]>a[j]) { tmp=a[i]; a[i]=a[j]; a[j]=tmp; if(b[i]>b[j]) { tmp=b[i]; b[i]=b[j]; b[j]=tmp; } } printf("\n Array 1: "); for(i=0;i<5;i++) {printf(" %d |",a[i]);} printf("\n Array 2: "); for(i=0;i<5;i++) {printf(" %d |",b[i]);} for(i=j=k=0;k<10;) { if(a[i]<=b[j]) { c[k]=a[i]; i++; k++;

}

}

}

Page 7 of 50


Assignment â&#x20AC;&#x201C; DFS Name: Priyank Patel S.Y.BCA - 45 else {

c[k]=b[j]; j++; k++; if(i==5 || j==5) break;

}

printf("\n IT :"); for(t=0;t<k;t++) { printf(" %d ",c[t]); } printf("\n"); } if(i==5) { for(k;k<10;) { c[k]=b[j]; k++;j++; printf("\n IT :"); for(t=0;t<k;t++) { printf(" %d ",c[t]); } printf("\n"); } if(j==5) {

for(k;k<10;) {

c[k]=a[i]; i++;k++;

}

}

printf("\n IT :"); for(t=0;t<k;t++) { printf(" %d ",c[t]); } printf("\n"); } printf("The Array : "); for(i=0;i<10;i++) printf(" %d ",c[i]); getch(); }

Page 8 of 50


Assignment â&#x20AC;&#x201C; DFS Name: Priyank Patel S.Y.BCA - 45

2. execute a program which sort data using Quick sort method: (Using Recursive method) è #include<stdio.h> int flag; main() { int a[30],n,i; clrscr(); printf("enter the elements you want:"); scanf("%d",&n); for(i=0;i<n;i++) { printf("enter elements %d : " ,i+1); scanf("%d",&a[i]); } printf("Unsorted list is : \n"); display(a,0,n-1); printf("\n"); quick(a,0,n-1); printf("\n sorted list is : \n"); display(a,0,n-1); printf("\n"); getch(); } quick(int arr[],int low,int up) { int piv,tmp,left,right; flag=0; left=low; right=up; piv=low; if(low>=up) return; printf("\n sublist \n"); display(arr,low,up); while(flag==0) { while(arr[piv]<=arr[right] && piv != right) { right--; } if(piv==right) flag=1; if(arr[piv]>arr[right]) { tmp=arr[piv]; arr[piv]=arr[right]; arr[right]=tmp; piv=right; printf("\n -> pivot is %d ->",arr[piv]); display(arr,low,up);

Page 9 of 50


Assignment â&#x20AC;&#x201C; DFS Name: Priyank Patel S.Y.BCA - 45 printf("\n");

}

while(arr[piv]>=arr[left] && left != piv) { left++;} if(piv==left) flag=1; if(arr[piv]<arr[left]) { tmp=arr[piv]; arr[piv]=arr[left]; arr[left]=tmp; piv=left; printf("\n -> pivot is %d ->", arr[piv]); display(arr,low,up); printf("\n"); } } printf("\n -> pivot is %d ->",arr[piv]); display(arr,low,up); printf("\n\n \t partition..."); quick(arr,low,piv-1); quick(arr,piv+1,up); } display(int arr[],int low,int up) { int i; for(i=low;i<=up;i++) printf(": %d ",arr[i]); }

Page 10 of 50


Assignment â&#x20AC;&#x201C; DFS Name: Priyank Patel S.Y.BCA - 45 3. Execute program which sort data using Heap sort method. 4. Execute program for Binary search using 1 D array. #include<conio.h> main() { int a[10],i,val,ub=10,lb=0,mid; clrscr(); for(i=0;i<10;i++) { printf("pls enter a value :"); scanf("%d",&a[i]); } printf("pls enter a value which search:"); scanf("%d",&val); while(1) { mid=(ub+lb)/2; if(mid==val) {printf("value found on %d",mid);break;} else if(mid>val) {ub=mid-1;} else {lb=mid+1;} } getch(); }

Page 11 of 50


Assignment â&#x20AC;&#x201C; DFS Name: Priyank Patel S.Y.BCA - 45

5. Write a menu base program for sorting and searching method which execute following function : è 1. Bubble sort: 2. Binary search: 3. Exit #include<conio.h> int a[5]; main() { int i; for(i=0;i<5;i++) { printf("Pls enter a number"); scanf("%d",&a[i]); } menu(); } menu() { int o; clrscr(); printf("1. Bubble Sort \n"); printf("2. Binary Search \n"); printf("3. Exit\n"); scanf("%d",&o); switch(o) { case 1: buble(); menu(); break; case 2: bin(); menu(); break; case 3: exit(o); menu(); break; defalut: printf("Option value does not exist"); } } buble() { int tmp,i,j; for(i=0;i<4;i++) { for(j=0;j<4;j++) { if(a[j]>a[j+1]) {

break;

Page 12 of 50


Assignment â&#x20AC;&#x201C; DFS Name: Priyank Patel S.Y.BCA - 45 tmp=a[j]; a[j]=a[j+1]; a[j+1]=tmp; } } } printf("Array after sort: "); for(i=0;i<5;i++) {printf("%d",a[i]);} getch(); } bin() { int item,ub=5,lb=0,mid; printf("Pls enter a value which u found:"); scanf("%d",&item); while(1) { mid=(ub+lb)/2; if(a[mid]==item) {printf("Value is found on %d Position.",mid); break;} else if(a[mid]>item) {ub--;} else lb++; } getch(); }

Page 13 of 50


Assignment â&#x20AC;&#x201C; DFS Name: Priyank Patel S.Y.BCA - 45

6. Write a menu base program for sorting and searching method which execute following function : è 1. Bubble sort: 2. Sequential search: 3. Exit #include<conio.h> #define size 5 int a[size],i,j; main() { for(i=0;i<size;i++) {printf("pls enter a elements ."); scanf("%d",&a[i]);} menu(); getch(); } menu() { int o; clrscr(); printf("1. Bubble sort \n"); printf("2. Sequencial Search \n"); printf("3. Exit \n"); printf("choose any one..."); scanf("%d",&o); switch(o) {case 1: bubble(); menu(); break; case 2: search(); menu(); break; case 3: exit(0); default: printf("please choose any one...\n"); }

menu(); break;}

bubble() { int tmp; for(i=0;i<size;i++) { for(j=0;j<size;j++) { if(a[i]<a[j]) {tmp=a[i]; a[i]=a[j]; a[j]=tmp; } } }

Page 14 of 50


Assignment â&#x20AC;&#x201C; DFS Name: Priyank Patel S.Y.BCA - 45 for(i=0;i<size;i++) { printf(" %d ",a[i]); getch(); }

}

search() { int s; printf("pls enter a value which you want to search: "); scanf("%d",&s); for(i=0;i<size;i++) { if(a[i]==s) {printf("the value is founded on %d ",i+1); break;} } getch(); }

Page 15 of 50


Assignment â&#x20AC;&#x201C; DFS Name: Priyank Patel S.Y.BCA - 45

7. Write a menu base program which sort data using following method: è 1. Bubble sort: 2. Insertion sort: 3. Exit #include<conio.h> #define size 5 int a[size],i,j; main() { for(i=0;i<size;i++) {printf("pls enter a elements ."); scanf("%d",&a[i]);} menu(); getch(); } menu() { int o; clrscr(); printf("1. Bubble sort \n"); printf("2. Insertion Sort \n"); printf("3. Exit \n"); printf("choose any one..."); scanf("%d",&o); switch(o) {case 1: bubble(); menu(); break; case 2: ins(); menu(); break; case 3: exit(0); default: printf("please choose any one...\n"); }

menu(); break;}

bubble() { int tmp; for(i=0;i<size;i++) { for(j=0;j<size;j++) { if(a[i]<a[j]) {tmp=a[i]; a[i]=a[j]; a[j]=tmp; } } } for(i=0;i<size;i++)

Page 16 of 50


Assignment â&#x20AC;&#x201C; DFS Name: Priyank Patel S.Y.BCA - 45 {

printf(" %d ",a[i]);

}

getch(); } ins() { int s,tmp; for(i=0;i<size;i++) { for(j=0;j<=i;j++) { if(a[i]<a[j]) { tmp=a[i]; a[i]=a[j]; a[j]=tmp; } } } for(i=0;i<size;i++) printf("%d ",a[i]); getch(); }

Page 17 of 50


Assignment â&#x20AC;&#x201C; DFS Name: Priyank Patel S.Y.BCA - 45

8. write è 1. 2. 3.

menu base program which sort data using following method: Bubble sort: Selection sort: Exit

#include<conio.h> #define size 5 int a[size],i,j; main() { for(i=0;i<size;i++) {printf("Pls enter a elements ."); scanf("%d",&a[i]);} menu(); getch(); } menu() { int o; clrscr(); printf("1. Bubble sort \n"); printf("2. Selection Sort \n"); printf("3. Exit \n"); printf("choose any one..."); scanf("%d",&o); switch(o) {case 1: bubble(); menu(); break; case 2: sel(); menu(); break; case 3: exit(0); default: printf("please choose any one...\n"); }

menu(); break;}

bubble() { int tmp; for(i=0;i<size;i++) { for(j=0;j<size;j++) { if(a[i]<a[j]) {tmp=a[i]; a[i]=a[j]; a[j]=tmp; } } } for(i=0;i<size;i++)

Page 18 of 50


Assignment â&#x20AC;&#x201C; DFS Name: Priyank Patel S.Y.BCA - 45 printf(" %d ",a[i]); getch(); } sel() { int tmp; for(i=0;i<size;i++) { for(j=i+1;j<size;j++) { if(a[i]>a[j]) {tmp=a[i]; a[i]=a[j]; a[j]=tmp; } } for(i=0;i<size;i++) printf(" %d ",a[i]); getch(); }

}

Page 19 of 50


Assignment â&#x20AC;&#x201C; DFS Name: Priyank Patel S.Y.BCA - 45

9. write è 1. 2. 3.

a menu base program which sort data using following method: Merge sort: Selection sort: Exit

#include<stdio.h> #define size 10 #define size1 5 int a[size1],b[size1],c[size],i,j,k,tmp; main() { clrscr(); for(i=0;i<size1;i++) { printf("Pls enter a elements for 1st array : "); scanf("%d",&a[i]); } for(i=0;i<size1;i++) { printf("Pls enter a elements for 2nd array : "); scanf("%d",&b[i]); } menu(); } menu() { int o; clrscr(); printf("1. Merge Sort \n"); printf("2. Selection Sort \n"); printf("3. Exit \n"); printf("4. Pls Choose any one..."); scanf("%d",&o); switch(o) {case 1: merge(); menu(); break; case 2: select(); menu(); break; case 3: exit(0); break; default: printf("Pls choose any one...."); getch(); menu(); } select() { for(i=0;i<size1;i++) {

Page 20 of 50

break;}


Assignment â&#x20AC;&#x201C; DFS Name: Priyank Patel S.Y.BCA - 45 for(j=i+1;j<size1;j++) { if(a[i]>a[j]) {tmp=a[i]; a[i]=a[j]; a[j]=tmp;} if(b[i]>b[j]) {tmp=b[i]; b[i]=b[j]; b[j]=tmp;} } } printf("\n\n Array 1.\n"); for(i=0;i<size1;i++) printf(" %d ",a[i]); printf("\n\n Array 2.\n"); for(i=0;i<size1;i++) printf(" %d ",b[i]); getch(); } merge() { for(i=0;i<size1;i++) { for(j=i+1;j<size1;j++) { if(a[i]>a[j]) {tmp=a[i]; a[i]=a[j]; a[j]=tmp;} if(b[i]>b[j]) {tmp=b[i]; b[i]=b[j]; b[j]=tmp;} } } printf("\n\n Array 1.\n"); for(i=0;i<size1;i++) printf(" %d ",a[i]); printf("\n\n Array 2.\n"); for(i=0;i<size1;i++) printf(" %d ",b[i]); for(i=j=k=0;i<size;)

Page 21 of 50


Assignment â&#x20AC;&#x201C; DFS Name: Priyank Patel S.Y.BCA - 45 { if(a[j]>=b[k]) {c[i]=b[k]; k++;i++;} if(a[j]<b[k]) {c[i]=a[j]; i++;j++;} if(j==size1 || k==size1) break; } if(j==size1) {

} if(k==size1) {

for(i;i!=size;) {c[i]=b[k]; i++;k++; }

for(i;i!=size;) {c[i]=a[j]; i++; j++;

}

} printf("\n\n Merge Array .\n"); for(i=0;i<size;i++) printf(" %d ",c[i]); getch(); }

Page 22 of 50


Assignment â&#x20AC;&#x201C; DFS Name: Priyank Patel S.Y.BCA - 45

10. write è 1. 2. 3.

a menu base program which sort data using following method: Merge sort: Bubble sort: Exit

#include<stdio.h> #define size 10 #define size1 5 int a[size1],b[size1],c[size],i,j,k,tmp; main() { clrscr(); for(i=0;i<size1;i++) { printf("Pls enter a elements for 1st array : "); scanf("%d",&a[i]); } for(i=0;i<size1;i++) { printf("Pls enter a elements for 2nd array : "); scanf("%d",&b[i]); } menu(); } menu() { int o; clrscr(); printf("1. Merge Sort \n"); printf("2. Bubble Sort \n"); printf("3. Exit \n"); printf(" Pls Choose any one..."); scanf("%d",&o); switch(o) {case 1: merge(); menu(); break; case 2: bubble(); menu(); break; case 3: exit(0); break; default: printf("Pls choose any one...."); getch(); menu(); } bubble() { int temp; for(i=0;i<size1-1;i++)

Page 23 of 50

break;}


Assignment â&#x20AC;&#x201C; DFS Name: Priyank Patel S.Y.BCA - 45 {

for(j=0;j<size1-1;j++) { if(a[j]>a[j+1]) {temp=a[j]; a[j]=a[j+1]; a[j+1]=temp;} if(b[j]>b[j+1]) {temp=b[j]; b[j]=b[j+1]; b[j+1]=temp;} }

} printf("\n\n Array 1.\n"); for(i=0;i<size1;i++) printf(" %d ",a[i]); printf("\n\n Array 2.\n"); for(i=0;i<size1;i++) printf(" %d ",b[i]); getch(); } merge() { for(i=0;i<size1;i++) { for(j=i+1;j<size1;j++) { if(a[i]>a[j]) {tmp=a[i]; a[i]=a[j]; a[j]=tmp;} if(b[i]>b[j]) {tmp=b[i]; b[i]=b[j]; b[j]=tmp;} } } printf("\n\n Array 1.\n"); for(i=0;i<size1;i++) printf(" %d ",a[i]); printf("\n\n Array 2.\n"); for(i=0;i<size1;i++) printf(" %d ",b[i]);

Page 24 of 50


Assignment â&#x20AC;&#x201C; DFS Name: Priyank Patel S.Y.BCA - 45 for(i=j=k=0;i<size;) { if(a[j]>=b[k]) {c[i]=b[k]; k++;i++;} if(a[j]<b[k]) {c[i]=a[j]; i++;j++;} if(j==size1 || k==size1) break; } if(j==size1) {

} if(k==size1) {

for(i;i!=size;) {c[i]=b[k]; i++;k++; }

for(i;i!=size;) {c[i]=a[j]; i++; j++;

}

} printf("\n\n Merge Array .\n"); for(i=0;i<size;i++) printf(" %d ",c[i]); getch(); }

Page 25 of 50


Assignment â&#x20AC;&#x201C; DFS Name: Priyank Patel S.Y.BCA - 45

11. Write a menu base program for following : è 1. Merge sort: 2. Insertion sort: 3. Exit #include<conio.h> #define size 10 #define size1 5 int a[5],b[5],c[5],i,j,k,tmp; main() { int o; printf("\nArray 1 :\n"); for(i=0;i<size1;i++) { printf("Pls enter a elements :"); scanf("%d",&a[i]); } printf("\nArray 2:\n"); for(i=0;i<size1;i++) { printf("Pls enter a elements :"); scanf("%d",&b[i]); } while (1) { clrscr(); printf("1. Merge sort :\n"); printf("2. Instertion Sort\n"); printf("3. Exit\n"); printf("\n Choose any one.."); scanf("%d",&o); switch(o) { case 1: merge(); break; case 2: ins(); break; case 3: exit(0); default : printf("Choose valid value"); } } } merge() { printf("Merge Sort:\n");

Page 26 of 50

break;


Assignment â&#x20AC;&#x201C; DFS Name: Priyank Patel S.Y.BCA - 45 for(i=0;i<size1;i++) { for(j=i+1;j<size1;j++) { if(a[i]>a[j]) {tmp=a[i]; a[i]=a[j]; a[j]=tmp;} if(b[i]>b[j]) {tmp=b[i]; b[i]=b[j]; b[j]=tmp;} } } printf("\n\n Array 1.\n"); for(i=0;i<size1;i++) printf(" %d ",a[i]); printf("\n\n Array 2.\n"); for(i=0;i<size1;i++) printf(" %d ",b[i]); for(i=j=k=0;i<size;) { if(a[j]>=b[k]) {c[i]=b[k]; k++;i++;} if(a[j]<b[k]) {c[i]=a[j]; i++;j++;} if(j==size1 || k==size1) break; } if(j==size1) {

} if(k==size1) {

for(i;i!=size;) {c[i]=b[k]; i++;k++; }

for(i;i!=size;) {c[i]=a[j]; i++; j++;

}

} printf("\n\n Merge Array .\n"); for(i=0;i<size;i++) printf(" %d ",c[i]);

Page 27 of 50


Assignment â&#x20AC;&#x201C; DFS Name: Priyank Patel S.Y.BCA - 45 getch(); } ins() { int s,tmp; printf("Insertion Sort:\n"); for(i=0;i<size1;i++) { for(j=0;j<=i;j++) { if(a[i]<a[j]) {tmp=a[i]; a[i]=a[j]; a[j]=tmp;} } } printf("Array 1 : "); for(i=0;i<size1;i++) printf("%d ",a[i]); getch(); }

Page 28 of 50


Assignment â&#x20AC;&#x201C; DFS Name: Priyank Patel S.Y.BCA - 45

12. Write a menu base program for following : è 1. Insertion sort: 2. Sequential Search: 3. Exit #include<conio.h> #define size 10 #define size1 5 int a[5],b[5],c[5],i,j,k,tmp; main() { int o; printf("\nArray:\n"); for(i=0;i<size1;i++) { printf("Pls enter a elements :"); scanf("%d",&a[i]); } while (1) { clrscr(); printf("1. Insertion sort :\n"); printf("2. Sequentional Search :\n"); printf("3. Exit\n"); printf("\n Choose any one.."); scanf("%d",&o); switch(o) { case 1: ins(); break; case 2: seq(); break; case 3: exit(0); default : printf("Choose valid value"); } } }

seq() { int val; printf("Enter a value which you want to search: "); scanf("%d",&val);

Page 29 of 50

break;


Assignment â&#x20AC;&#x201C; DFS Name: Priyank Patel S.Y.BCA - 45 printf("Value is founded on :\n\t Position :\tValue\n"); for(i=0;i<size1;i++) {if(a[i]==val) { printf("\t %d =\t %d\n",i+1,a[i]); } getch(); } ins() { int s,tmp; printf("Insertion Sort:\n"); for(i=0;i<size1;i++) { for(j=0;j<=i;j++) { if(a[i]<a[j]) {tmp=a[i]; a[i]=a[j]; a[j]=tmp;} } } printf("Array : "); for(i=0;i<size1;i++) printf("%d ",a[i]); getch(); }

Page 30 of 50

}


Assignment â&#x20AC;&#x201C; DFS Name: Priyank Patel S.Y.BCA - 45

13. Write a menu base program for sorting and searching method which execute following function : è 1. Insertion sort: 2. Binary Search: 3. Exit #include<conio.h> #define size 5 int a[size],i,j,val,c; void menu(); void ins(); void bin(); void main() { for(i=0;i<size;i++) {printf("pls enter a elements ."); scanf("%d",&a[i]);} menu(); getch(); } void menu() { int o; clrscr(); printf("1. Binary Search \n"); printf("2. Insertion Sort \n"); printf("3. Exit \n"); printf("choose any one..."); scanf("%d",&o); switch(o) {case 1: bin(); menu(); break; case 2: ins(); menu(); break; case 3: exit(0); default: printf("please choose any one...\n"); }

menu(); break;}

void bin() { int mid,lb=0,ub=size-1,tmp; for(i=0;i<4;i++) { for(j=i+1;j<5;j++)

Page 31 of 50


Assignment â&#x20AC;&#x201C; DFS Name: Priyank Patel S.Y.BCA - 45 {

if(a[i]>a[j]) {tmp=a[i];a[i]=a[j];a[j]=tmp;}

} } printf("pls enter a value which search:"); scanf("%d",&val); printf("\n\n After Sorted Array :\n"); for(i=0;i<5;i++) printf("| %d |",a[i]); while(c<100) { mid=(ub+lb)/2; if(a[mid]==val) {printf("\n\n Value found on %d",mid);break;} else if(a[mid]>val) {ub=mid-1;} else {lb=mid+1;} c++; } printf("\n\n Searching Finished....."); getch(); } void ins() { int tmp; for(i=0;i<size;i++) {for(j=0;j<=i;j++) {if(a[i]<a[j]) {tmp=a[i]; a[i]=a[j]; a[j]=tmp;} } } for(i=0;i<size;i++) printf("%d ",a[i]); getch(); }

Page 32 of 50


Assignment â&#x20AC;&#x201C; DFS Name: Priyank Patel S.Y.BCA - 45

14. Write a menu base program which sort data using following method: è 1. Insertion sort: 2. Selection sort: 3. Exit #include<conio.h> #define size 5 int a[size],i,j,k; main() { for(i=0;i<size;i++) {printf("pls enter a elements ."); scanf("%d",&a[i]);} menu(); getch(); } menu() { int o; clrscr(); printf("1. Selection sort \n"); printf("2. Insertion Sort \n"); printf("3. Exit \n"); printf("choose any one..."); scanf("%d",&o); switch(o) { case 1: sel(); menu(); break; case 2: ins(); menu(); break; case 3: exit(0); default: printf("please choose any one...\n"); }

menu(); break;}

sel() { int tmp; for(i=0;i<size-1;i++) {printf("\n Itereation....%d\n\t\t",i+1); for(k=0;k<size;k++) { printf("%d |",a[k]);} printf("\n"); for(j=i+1;j<size;j++) { if(a[i]>a[j]) {tmp=a[i]; a[i]=a[j];

Page 33 of 50


Assignment â&#x20AC;&#x201C; DFS Name: Priyank Patel S.Y.BCA - 45 a[j]=tmp; } } } for(i=0;i<size;i++) { printf(" %d ",a[i]); getch(); }

}

ins() { int s,tmp; for(i=0;i<size;i++) {printf("\n Itereation....%d\n\t\t",i+1); for(k=0;k<size;k++) { printf("%d |",a[k]);} printf("\n"); for(j=0;j<=i;j++) {if(a[i]<a[j]) {tmp=a[i]; a[i]=a[j]; a[j]=tmp;} } } for(i=0;i<size;i++) printf("%d ",a[i]); getch(); }

Page 34 of 50


Assignment â&#x20AC;&#x201C; DFS Name: Priyank Patel S.Y.BCA - 45

15. Write a menu base program for sorting and searching method which execute following function : è 1. Selection sort: 2. Binary search: 3. Exit #include<conio.h> #define size 5 int a[size],i,j,val,c; void menu(); void sel(); void bin(); void main() { for(i=0;i<size;i++) {printf("pls enter a elements ."); scanf("%d",&a[i]);} menu(); getch(); } void menu() { int o; clrscr(); printf("1. Binary Search \n"); printf("2. Selection Sort \n"); printf("3. Exit \n"); printf("choose any one..."); scanf("%d",&o); switch(o) {case 1: bin(); menu(); break; case 2: sel(); menu(); break; case 3: exit(0); default: printf("please choose any one...\n"); }

menu(); break;}

void bin() { int mid,lb=0,ub=size-1,tmp; for(i=0;i<4;i++)

Page 35 of 50


Assignment â&#x20AC;&#x201C; DFS Name: Priyank Patel S.Y.BCA - 45 {

for(j=i+1;j<5;j++) { if(a[i]>a[j]) {tmp=a[i];a[i]=a[j];a[j]=tmp;} }

} printf("pls enter a value which search:"); scanf("%d",&val); printf("\n\n After Sorted Array :\n"); for(i=0;i<5;i++) printf("| %d |",a[i]); while(c<100) { mid=(ub+lb)/2; if(a[mid]==val) {printf("\n\n Value found on %d",mid);break;} else if(a[mid]>val) {ub=mid-1;} else {lb=mid+1;} c++; } printf("\n\n Searching Finished....."); getch(); } void sel() { int tmp; for(i=0;i<size;i++) {for(j=0;j<=i;j++) {if(a[i]<a[j]) {tmp=a[i]; a[i]=a[j]; a[j]=tmp;} } } for(i=0;i<size;i++) printf("%d ",a[i]); getch(); }

Page 36 of 50


Assignment – DFS Name: Priyank Patel S.Y.BCA - 45 Stack 1. Execute a menu program for stack operations. 1. push 2. pop 3. peep 4. Display 5. Exit è #include<stdio.h> #include<conio.h> int a[5],top=-1,i,j,item,k; main() { clrscr(); printf(" 1. Push \n 2. Pop \n 3.Peep \n 4. Display \n 5. Exit\n Select Any One :"); scanf("%d",&i); switch(i) { case 1 : push(); break; case 2 : pop(); break; case 3 : peep(); break; case 4 : disp(); break; case 5 : exit(0); break; } main(); } push() { if(top<4) { printf("Enter Elements : "); scanf("%d",&item); top++; a[top]=item; } else { printf("Over Flow"); getch(); } } pop() { if(top>=0)

Page 37 of 50


Assignment â&#x20AC;&#x201C; DFS Name: Priyank Patel S.Y.BCA - 45 top--; else {

printf("under flow"); getch(); }

} peep() { int val,tmp,i,flag=0; printf("Enter a value which u search: "); scanf("%d",&val); tmp=top; for(i=top;i>=0;i--) { printf(" %d \n",a[i]); if(a[i]==val) flag=1; } if(flag==1) printf("\n Value is found..... "); else printf("\n Val is not found....."); getch(); } disp() { printf("The Array is : "); for(j=top;j>=0;j--) printf("\n\t\t\t %d ",a[j]); getch(); }

Page 38 of 50


Assignment – DFS Name: Priyank Patel S.Y.BCA - 45 2. Execute a menu program for stack operations. 1. push 2. peep 3. Change 4. Display 5. Exit è #include<stdio.h> #include<conio.h> int a[5],top=-1,i,j,item,k; main() { clrscr(); printf(" 1. Push \n 2. Change \n 3.Peep \n 4. Display \n 5. Exit\n Select Any One :"); scanf("%d",&i); switch(i) { case 1 : push(); break; case 2 : change(); break; case 3 : peep(); break; case 4 : disp(); break; case 5 : exit(0); break; } main(); } push() { if(top<4) { printf("Enter Elements : "); scanf("%d",&item); top++; a[top]=item; } else { printf("Over Flow"); getch(); } } change() { int pos,val; if(top>=0)

Page 39 of 50


Assignment â&#x20AC;&#x201C; DFS Name: Priyank Patel S.Y.BCA - 45 { printf("Enter a position u want to change...."); scanf("%d",&pos); printf("Enter a value to replace"); scanf("%d",&val); a[pos]=val; printf("Successfully changed....."); } else { printf("under flow"); getch();

}

} peep() { int val,tmp,i,flag=0; printf("Enter a value which u search: "); scanf("%d",&val); tmp=top; for(i=top;i>=0;i--) { printf(" %d \n",a[i]); if(a[i]==val) flag=1; } if(flag==1) printf("\n Value is found..... "); else printf("\n Val is not found....."); getch(); } disp() { printf("The Array is : "); for(j=top;j>=0;j--) printf("\n\t\t\t %d ",a[j]); getch(); }

Page 40 of 50


Assignment – DFS Name: Priyank Patel S.Y.BCA - 45

3. Execute a menu program for stack operations. 1. push 2. pop 3. Change 4. Display 5. Exit è #include<stdio.h> #include<conio.h> int a[5],top=-1,i,j,item,k; main() { clrscr(); printf(" 1. Push \n 2. Pop \n 3.change \n 4. Display \n 5. Exit\n Select Any One :"); scanf("%d",&i); switch(i) { case 1 : push(); break; case 2 : pop(); break; case 3 : change(); break; case 4 : disp(); break; case 5 : exit(0); break; } main(); } push() { if(top<4) { printf("Enter Elements : "); scanf("%d",&item); top++; a[top]=item; } else { printf("Over Flow"); getch(); } } pop() { if(top>=0) top--;

Page 41 of 50


Assignment â&#x20AC;&#x201C; DFS Name: Priyank Patel S.Y.BCA - 45 else {

printf("under flow"); getch(); }

} change() { int pos,val; if(top>=0) { printf("Enter a position u want to change...."); scanf("%d",&pos); printf("Enter a value to replace"); scanf("%d",&val); a[pos]=val; printf("Successfully changed....."); } else { printf("under flow"); } getch(); } disp() { printf("The Array is : "); for(j=top;j>=0;j--) printf("\n\t\t\t %d ",a[j]); getch(); }

Page 42 of 50


Assignment – DFS Name: Priyank Patel S.Y.BCA - 45

4. Execute a menu program for stack operations. 1. push 2. pop 3. peep 4. Change 5. Display 6. Exit è #include<stdio.h> #include<conio.h> int a[5],top=-1,i,j,item,k; main() { clrscr(); printf(" 1. Push \n 2. Pop \n 3.change \n 4. Peep \n 5. Display \n 6. Exit\n Select Any One :"); scanf("%d",&i); switch(i) { case 1 : push(); break; case 2 : pop(); break; case 3 : change(); break; case 4 : peep(); break; case 5 : disp(); break; case 6 : exit(0); break; } main(); } push() { if(top<4) { printf("Enter Elements : "); scanf("%d",&item); top++; a[top]=item; } else { printf("Over Flow"); getch(); } } peep() { int val,tmp,i,flag=0;

Page 43 of 50


Assignment â&#x20AC;&#x201C; DFS Name: Priyank Patel S.Y.BCA - 45 printf("Enter a value which u search: "); scanf("%d",&val); tmp=top; for(i=top;i>=0;i--) { printf(" %d \n",a[i]); if(a[i]==val) flag=1; } if(flag==1) printf("\n Value is found..... "); else printf("\n Val is not found....."); getch(); }

pop() { if(top>=0) top--; else {

printf("under flow"); getch(); }

} change() { int pos,val; if(top>=0) { printf("Enter a position u want to change...."); scanf("%d",&pos); printf("Enter a value to replace"); scanf("%d",&val); a[pos]=val; printf("Successfully changed....."); } else { printf("under flow"); } getch(); } disp() { printf("The Array is : "); for(j=top;j>=0;j--) printf("\n\t\t\t %d ",a[j]); getch(); }

Page 44 of 50


Assignment â&#x20AC;&#x201C; DFS Name: Priyank Patel S.Y.BCA - 45

5. Execute a program which reverses numbers using stack. è #include<stdio.h> #include<conio.h> int a[5],top=-1,i,j,item,k; main() { clrscr(); printf(" 1. Push \n 2. Reverse \n 3. Exit\n Select Any One :"); scanf("%d",&i); switch(i) { case 1 : push(); break; case 2 : reverse(); break; case 3 : exit(0); break; } main(); } push() { if(top<4) { printf("Enter Elements : "); scanf("%d",&item); top++; a[top]=item; } else { printf("Over Flow"); getch(); } } reverse() { printf("The Number in reverse is : "); for(j=top;j>=0;j--) printf("%d",a[j]); getch(); }

Page 45 of 50


Assignment â&#x20AC;&#x201C; DFS Name: Priyank Patel S.Y.BCA - 45

6. Execute a program which checks the given number is palindrome or not. è #include<conio.h> #include<stdio.h> #define n 5 void main() { int a[n],top,i,tmp[n],c=0,nc=0; clrscr(); printf("Enter a value"); for(i=0;i<n;i++) { scanf("%d",&a[i]); printf("\n\n Original Stack : "); for(i=0;i<n;i++) { printf("%d",a[i]); top=n-1; for(i=0;i<n;i++) { tmp[top]=a[i]; top--; }

}

}

printf("\n\n Reverse Stack : "); for(i=0;i<n;i++) { printf("%d",tmp[i]); } for(i=0;i<n;i++) { if(a[i]==tmp[i]) c++; } if(c==5) printf("\n Peline drome....."); else printf("\n Not Peline drome..."); getch(); }

Page 46 of 50


Assignment â&#x20AC;&#x201C; DFS Name: Priyank Patel S.Y.BCA - 45

Queue 1. Execute program for simple queue operation which perform following operation. è 1. Insert 2. Delete 3. Display 4. Exit #include<stdio.h> #include<conio.h> #define size 5 int r=-1,f=-1; int sq[size]; void insert() { if(r==size-1) { printf("\n Queue is overflow!.......!!!"); getch(); return; } else { if(f==-1 && r==-1) { f=0; } r++; printf("pls enter a value :"); scanf("%d",&sq[r]); } getch(); } void delete() { if(f==-1 || f>r) { printf("Queue is underflow.......!"); getch(); return ; } else {

Page 47 of 50


Assignment â&#x20AC;&#x201C; DFS Name: Priyank Patel S.Y.BCA - 45 printf("\n \t %d is deleted....!",sq[f]); f++; } getch(); } void display() { int i; if(f==-1 || f>r) { printf("\n Queue is empty..!!"); } else { printf("\n-------------\n"); for(i=f;i<=r;i++) printf("| %d",sq[i]); printf("|"); printf("\n-------------\n"); } getch(); } void main() { int o; clrscr(); printf("MENU \n"); printf("1. Insert Elements \n"); printf("2. Delete elements from simple queue \n"); printf("3. Display Queue \n"); printf("4. Exit \n"); printf("pls enter your choice :"); scanf("%d",&o); switch(o) { case 1: case 2: case 3: case 4: default:

insert(); delete(); display(); exit(0);

main(); main(); main();

printf("Wrong Choice\n");

break; break; break; break; getch(); main();

break; } }

Page 48 of 50


Assignment â&#x20AC;&#x201C; DFS Name: Priyank Patel S.Y.BCA - 45 2. Execute program for Circular queue operation which perform following operation. è 1. Insert 2. Delete 3. Display 4. Exit #include<conio.h> #include<stdio.h> #define size 5 int r=-1,f=-1; int cq[size]; void insert() { int item; if((f==0 && r==size-1) || (f==r+1)) {printf("\n Queue is overflow.......!"); getch(); return; } else { if(f==-1 && r==-1) {f=0; r=0; } else { if(r==size-1 && f!=0) r=0; else r++; printf("Enter value :"); scanf("%d",&cq[r]); } getch(); }

}

void del() { if(f==-1) {

printf("\n Queue is Underflow..........!"); getch(); return; } printf("\n \t %d is deleted........!",cq[f]); if(f==r) {f=-1;r=-1; } else { if(f==size-1) f=0; else f++; } getch(); }

Page 49 of 50


Assignment â&#x20AC;&#x201C; DFS Name: Priyank Patel S.Y.BCA - 45 void display() { int i; if(f==-1) { printf("\n Queue is Empty..........!"); getch(); return; } printf("\n------------------\n"); if(f<=r) { for(i=f;i<=r;i++) printf("| %d",cq[i]); } else if(f>r) { for(i=0;i<=r;i++) printf("| %d",cq[i]); for(i=f;i<=size-1;i++) printf("| %d",cq[i]); } printf("|"); printf("\n-----------------------\n"); getch(); } void main() { int o; clrscr(); printf("1. INSERT \n"); printf("2. DELETE \n"); printf("3. DISPLAY \n"); printf("4. EXIT \n"); printf("Enter your choice :"); scanf("%d",&o); switch(o) { case 1: insert(); main(); break; case 2: del(); main(); break; case 3: display(); main(); break; case 4: exit(0); break; default: printf("Wrong Choice.......!"); break; } }

Page 50 of 50


All DFS Programs