Вы находитесь на странице: 1из 9

1. Write a C program to search for an element in an array using binary search.

#include<stdio.h> int main(){ int a[10],i,n,m,c,l,u; printf("Enter the size of an array =>"); scanf("%d",&n); printf("\nEnter the elements of an array =>"); for(i=0;i<n;i++){ scanf("%d",&a[i]); } printf("\nThe elements of an array are =>"); for(i=0;i<n;i++){ printf(" %d",a[i]); } printf("\nEnter the number to be search =>"); scanf("%d",&m); l=0,u=n-1; c=binary(a,n,m,l,u); if(c==0) printf("\nThe number is not in the list"); else printf("\nThe number is found"); return 0; }

int binary(int a[],int n,int m,int l,int u)

{ int mid,c=0; if(l<=u){ mid=(l+u)/2; if(m==a[mid]) { c=1; } else if(m<=a[mid]) { return binary(a,n,m,l,mid-1); } else return binary(a,n,m,mid+1,u); } else return c; }

</n;i++){ </n;i++){ </stdio.h>

2. Write a c Program to search for an element using sequential search.


void main(){ int a[10],i,n,m,c=0; clrscr(); printf("Enter the size of an array"); scanf("%d",&n); printf("\nEnter the elements of the array"); for(i=0;i<=n-1;i++){ scanf("%d",&a[i]); } printf("\nThe elements of an array are"); for(i=0;i<=n-1;i++){ printf(" %d",a[i]); } printf("\nEnter the number to be search"); scanf("%d",&m); for(i=0;i<=n-1;i++) { if(a[i]==m) { c=1; break; } }

if(c==0) printf("\nThe number is not in the list"); else printf("\nThe number is found"); getch(); }

#include<stdio.h> #include<conio.h> void main() { clrscr(); int i,n,item,a[20]; printf("\nEnter no of elements="); scanf("%d",&n); printf("\nEnter %d elements=",n); for(i=0;i<n;i++) { scanf("%d",&a[i]); } printf("\nEnter the element to be search="); scanf("%d",&item); for(i=0;i<n;i++) { if(a[i]==item) { printf("\n\t%d is present at position %d",a[i],i+1); break; } } if(i==n) printf("\nElement is not Present"); getch(); }

3. Write a C program to creat file N students, it should contain ROllno, Name ,marks in two subjects, Using the above created file, create an output file which contains Rollno, Name, marks in subjects, Total and average.

4. Write a C program to sort a list of N elements using Bubble sort Technique.


#include<stdio.h>
#include<conio.h> main() { int arr[50],temp,i,j,n; clrscr(); printf("\nEnter any Value less Than 50"); scanf("%d",&n); printf("\n\tEnter The Values into ARRAY "); for(i=0;i<n;i++) { printf("\n\n Enter Element no %d: ",i+1); scanf("%d",&arr[i]); } for(i=1;i<n;i++) { for(j=0;j<n-i;j++) { if(arr[j] >arr[j+1]) { temp=arr[j]; arr[j]=arr[j+1]; arr[j+1]=temp; } } } printf("\n\n-- Sorted Series --"); for(i=0;i<n;i++) { printf("\n %d",arr[i]); } getch();

5. Write a C program to Demonstrate the working of staff of size N using an array the elements of the staff may assume to be of type integer, the operations to be supported

are 1. PUSH 2. POP 3. DISPLAY. The program to should print the appropriate message for stack is underflow and overflow. 6. Write a C program to convert and print valid fully parenthesized infix arithmetic expression to postfix. 7. Write a C program to sort a list of N elements using Merge sort Algorithm. 8. Write a c Program to sort a list of N elements using quick sort algorithm. 9. Write a C program to sort a list of N elements of integer type using selection sort. 10. Write a c program to find the Binomial Coefficient using recursion.
#include<stdio.h>
int fact(int); void main() { int n,r,f; printf("enter value for n & r\n"); scanf("%d%d",&n,&r); if(n<r)

printf("invalid input"); else f=fact(n)/(fact(n-r)*fact(r)); printf("binomial coefficient=%d",f); } int fact(int x) { if(x>1) return x*fact(x-1); else return 1; }

11. Write a C program to simulate the working of towers of Hanoi for N disks, print the total number of moves taken.
#include "stdio.h" void towers(int,char,char,char); void towers(int n,char frompeg,char topeg,char auxpeg) { /* If only 1 disk, make the move and return */ if(n==1) { printf("\nMove disk 1 from peg %c to peg %c",frompeg,topeg); return; } /* Move top n-1 disks from A to B, using C as auxiliary */ towers(n-1,frompeg,auxpeg,topeg); /* Move remaining disks from A to C */ printf("\nMove disk %d from peg %c to peg %c",n,frompeg,topeg); /* Move n-1 disks from B to C using A as auxiliary */ towers(n-1,auxpeg,topeg,frompeg); } main() { int n; printf("Enter the number of disks : "); scanf("%d",&n); printf("The Tower of Hanoi involves the moves :\n\n"); towers(n,'A','C','B'); return 0; }

12. Write a C program to simulate the working of an Queue using an array Provide the operations QINSERT, QDELETE and QDISPLAY, check the Queue status for empty and full. 13. Write a C program to simulate the working of an CircularQueue using an array Provide the operations CQINSERT, CQDELETE and CQDISPLAY, check the CircularQueue status for empty and full. 14. Write a C program to construct a single linked list using dynamic variable ,list should contain the following information. 15. Using dynamic variables and pointers construct Binary search tree, it is found display

key found else insert the key in Binary search tree, while constructing the Binary search tree do not add any duplicate, display the tree using any of the traversal method.

Вам также может понравиться