Académique Documents
Professionnel Documents
Culture Documents
Index: Sr. no. 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. 21. 22. 23. 24. 25. 26. 27. 28. 29. Program name
Program to find the sum of two numbers Program to check whether given no. is odd/even Program to find the greatest of three numbers Program to find the percentage of marks obtained Program to find the roots of quadratic equation Program to add, subtract, multiply, divide two numbers using switch Program to find the average of n numbers using while loop Program to find the factorial using while loop Program to print Fibonacci series using do while loop Program to print palindrome number using do while loop Program to print 1,2,3...n using for loop Program to print asterisk (*) using for loop Program to calculate factorial using function Program to print the Fibonacci series using recursion Program to find the greatest of three numbers using function Program to search a given number from the given list using linear search Program to search a given number from the given list using binary search Program to sort a given list of numbers using bubble sort Program to find the sum of two matrices Program to find the product of two matrices Program for swapping numbers using pointer Program to find the average of n numbers using arrays Program to demonstrate use of address of operator (&) and indirection operator (*) for different purposes Program to demonstrate array elements are stored in contiguous memory location Program to sort the elements of an array using pointer Program to interchange value of two numbers using call by reference Program to show operators work in case of pointers Program to show how strings are initialized Program to copy a string to another using library function strcpy()
2
Program to reverse a given string without using library function Program to concatenate two strings without using library function Program to sort the characters of string alphabetically Program to access the member of structure in which we have pointer to a structure Program to calculate marks obtained by 10 students in different subjects
62 64 66 68 69
Output
Output
Output
10
Output
11
12
Output
13
#include<stdio.h> #include<conio.h> void main() { int a,b,choice,c; clrscr(); printf("\n Enter two numbers:"); scanf("%d%d",&a,&b); printf("\n 1. Addition"); printf("\n 2. Subtraction"); printf("\n 3. Multiplication"); printf("\n 4. Division"); printf("\n\n Enter your choice:"); scanf("%d",&choice); { switch(choice) { case 1:c=a+b; printf("\n Sum is %d",c); break; case 2:c=a-b; printf("\n Difference is %d",c); break; case 3:c=a*b; printf("\n Mulitplication is %d",c); break; case 4:c=a/b; printf("\n Quotient is %d",c); } } getch(); }
14
Output
15
#include<stdio.h> #include<conio.h> void main() { int n,i=1; float sum=0,avg,x; clrscr(); printf("\n Enter the value of n:"); scanf("%d",&n); while(i<=n) { printf("\n x="); scanf("%f",&x); sum+=x; i++; } avg=sum/n; printf("\n Avearage is %f",avg); getch(); }
16
Output
17
18
Output
19
#include<stdio.h> #include<conio.h> void main() { int a=0,b=1,c=1,n,count=3; clrscr(); printf("\n Enter the value of n:"); scanf("%d",&n); if(n==1) printf("0"); if(n==2) printf("1"); do { c=a+b; a=b; b=c; count++; } while(count<=n); if(c!=0) printf("\n %dth number is %d",n,c); getch(); }
20
Output
21
22
Output
23
24
Output
25
26
Output
27
28
Output
29
30
Output
31
32
Output
33
16. /* TITLE: Search a given number from a given list using linear search */
#include<stdio.h> #include<conio.h> void main() { int a[20],n,i,item,loc,count=0; clrscr(); printf("\n Enter number of elements : "); scanf("%d",&n); printf("\n Enter numbers : "); for(i=1;i<=n;i++) scanf("%d", &a[i]); printf("\n Enter item to be searched : "); scanf("%d", &item); for(i=1;i<=n;i++) { if (a[i] == item) { loc=i; printf("\n %d present at loc %d",item,loc); count++; } } if (count != 0) { printf("\n\n The number is present %d times",count); } else printf("\n Item is not present"); getch(); }
34
Output
35
17. /* TITLE: Search a given number from list using binary search */
#include<stdio.h> #include<conio.h> void main() { int a[20],n,i,loc=-1; int beg,end,mid,item; clrscr(); printf("\n Enter number of elements : "); scanf("%d",&n); printf("\n Enter sorted numbers : "); for(i=1;i<=n;i++) scanf("%d", &a[i]); printf("\n Enter element to be searched : "); scanf("%d", &item); beg=1; end=n; while(beg<=end) { mid = (beg+end)/2; if (a[mid] == item) { loc=mid; printf("\n Number is at %d loc",loc); break; } else if (a[mid]>item) end=mid-1; else beg=mid+1; } if (loc == -1) printf("\n Item is not in the list\n"); getch(); }
36
Output
37
38
Output
39
40
Output
41
Output
43
44
Output
45
46
Output
47
23. /* TITLE: Use of address operator(&) and indirection operator(*) for different purposes */
#include<stdio.h> #include<conio.h> void main() { int i=5,j=2,*ptr; clrscr(); ptr=&i; printf("\n Address of i= %u",&i); printf("\n\n Value stored in ptr= %d",ptr); printf("\n\n Value pointed by ptr= %d",*ptr); *ptr=10; printf("\n\n Value of i= %d",i); j=*ptr; printf("\n\n Value of j= %d",j); getch(); }
48
Output
49
24. /* TITLE: Demonstrate array elements are stored in contiguous memeory location */
#include<stdio.h> #include<conio.h> void main() { int x[5]={20,30,40,50,60}; int i; clrscr(); for(i=0;i<5;i++) printf("\n \n x[%d]= %d, &x[%d]= %u",i,x[i],i,&x[i]); getch(); }
50
Output
51
52
Output
53
54
Output
55
56
Output
57
58
Output
59
60
Output
61
62
Output
63
64
Output
65
66
Output
67
33. /* TITLE: Access the member of structure in which we have pointer to a structure */
#include<stdio.h> #include<conio.h> struct date { int dd; int mm; int yy; }; struct record { int acc_no; struct date l_pay; }; main() { struct record b,*p=&b; clrscr(); printf("\n Enter the values \n"); scanf("%d%d%d%d",&p->acc_no,&p->1_pay.dd,&p->1_pay.mm,&p->1_pay.yy); printf("\n Entered Values are \n"); printf("\n %d %d %d %d",p->acc_no,p->1_pay.dd,p->1_pay.mm,p->1_pay.yy); getch(); }
68
69
Output
70