Output: enter n: 3 enter number: 1 enter number: 2 enter number: 3 enter position: 2 enter value: 12 array elements after insertion: 1 2 12 3
3
2.Write a program to delete an element from one-dimensional array. #include<stdio.h> #include<conio.h> Void main() { int a[10]; int I,k,n,pos; clrscr(); printf(enter n:\n); scanf(%d,&n); for(i=0;i<n;i++) { printf(enter number:\n); scanf(%d,&a*i+); } printf(enter position:\n); scanf(%d,&pos); for(k=pos+1;k<n-1;k++) a[k-1]=a[k]; n=n-1; printf(array elements after deletion:\n); for(i=0;i<n;i++) { printf(%d,a*i+); printf(\n); } getch(); }
Output:
enter n: 3 enter number: 1 enter number: 2 enter number: 4
3 enter position: 1 array elements after deletion: 1 3
5
3.Write a program to sort array elements in ascending into one-dimensional array. #include<stdio.h> #include<conio.h> void main() { int a[10]; int i,j,n,temp; clrscr(); printf(enter n:\n); scanf(%d,&n); for(i=0;i<n;i++) { printf(enter number:\n); scanf(%d,&a*i+); } for(i=0;i<n;i++) { for(j=0;j<n;j++) { if(a[i]>a[j]) { temp=a[i]; a[i]=a[j]; a[j]=temp; } } } printf(array elements after sorting:\n); printf(ascending data:\n); for(i=0;i<n;i++) printf(%d\n,&a*i+); getch(); }
6
Output: enter n: 3 enter number: 1 enter number: 3 enter number: 2 array elements after sorting: ascending data: 1 2 3
7
4.write a program to merge two one-dimensional arrays.
#include<stdio.h> #include<conio.h> void main() { int a1[3],a2[2],a[5]; int i,j; clrscr(); printf(enter elements of first array:\n); for(i=0;i<3;i++); { Scanf(%d,&a1[i]); } printf(enter elements of second array:\n); for(i=0;i<2;i++) { scanf(%d,&a2*i+); } for(i=0,j=0;i<3;i++,j++) a[j]=a1[i]; for(i=0;i<2;i++,j++) a[j]=a2[i]; printf(\narray elements after merging:\n); for(j=0;j<5;j++) { printf(%d,a*j+; printf(\n); } getch(); }
8
Output: enter elements of first array: 1 2 3 enter elements of second array: 4 5 array elements after merging: 1 2 3 4 5
9
5.write a program to search given value in an one-dimensional array. #include<stdio.h> #include<conio.h> Void main() { int a[10]; int i,n,val,flag=0; clrscr(); printf(enter n:\n); scanf(%d,&n); printf(enter array elements :\n); for(i=0;i<n;i++) { scanf(%d,&a*i+); } printf(enter value:\n); scanf(%d,&val); for(i=0;i<n;i++) { if(val==a[i]){ printf(data found at %d\n,i); flag=1; } } if(!flag){ printf(data not found); } getch(); }
Output: enter n: 3 enter array elements: 1 2 3 enter value: 2 data found at 1 10
6.write a program to display matrix using array(2*2).
Output: enter array elements: a[0][0]=1 a[0][1]=2 a[1][0]=3 a[1][1]=4 matrix is: 1 2 3 4
11
7.Write a program to display sum of matrix(3*3). #include<stdio.h> #include<conio.h> Void main() { int a[3][3],b[3][3],c[3][3]; int i,j; clrscr(); printf(enter matrix a:\n); for(i=0;i<3;i++) { for(j=0;j<3;j++) { scanf(%d,&a*i+*j+); } } printf(enter matrix b:\n); for(i=0;i<3;i++) { for(j=0;j<3;j++) { scanf(%d,b*i+*j+); } } printf(sum of matrix is:\n); for(i=0;i<3;i++) { for(j=0;j<3;j++) { c[i][j]=a[i][j]+b[i][j]; } } for(i=0;i<3;i++) { for(j=0;j<3;j++) { printf(%4d,c*i+*j+); } printf(\n); } getch(); 12
}
Output: enter matrix a: 1 2 3 4 5 6 7 8 9 enter matrix b: 1 2 3 4 5 6 7 8 9 sum of matrix is: 2 4 6 8 10 12 14 16 18
13
8.Write a program to display multiplication of two matrix. #include<stdio.h> #include<conio.h> Void main() { int a[10][10],b[10][10],c[10][10]; int i,j,k,m,n,sum=0; clrscr(); printf(enter rows and columns:\n); scanf(%d %d,&m,&n); printf(enter matrix a:\n); for(i=0;i<m;i++) { for(j=0;j<n;j++) { scanf(%d,&a*i+*j+) } } printf(enter matrix b:\n); for(i=0;i<m;i++) { for(j=0;j<n;j++) { scanf(%d,&b*i+*j+); } } printf(multiplication of two matrix is:\n); for(i=0;i<m;i++) { for(j=0;j<n;j++) { sum=0; for(k=0;k<m;k++) sum=sum+a[i][k]*b[k][j]; c[i][j]=sum; printf(%d\t,c*i+*j+); } printf(\n); } getch(); } 14
Output: Enter rows and columns: 3 3 enter matrix a: 1 2 3 4 5 6 7 8 9 Enter matrix b: 1 2 3 4 5 6 7 8 9 multiplication of two matrix is: 30 36 42 66 81 96 102 126 150
15
9.Write a program to check upper triangle in the matrix using array. #include<stdio.h> #include<conio.h> Void main() { int a[10[10]; int i,j,m,n,flag=0; clrscr(); printf(enter rows and columns:\n); scanf(%d %d,&m,&n); printf(enter matrix :\n); for(i=0;i<m;i++) { for(j=0;j<n;j++) { Scanf(%d,&a*i+*j+); } } for(i=0;i<m;i++) { for(j=i;j<n;j++) { if(a[i][j]==0) { flag=1; go to outer: } } } outer: if(!flag) printf(matrix has upper triangle\n); else printf(matrix doesnt have upper triangle\n); getch(); }
10.Write a program to print length of string using scanf(). #include<stdio.h> #include<conio.h> Void main() { int i,count=0; char str[50]; clrscr(); puts(enter string:); scanf(%s,&str); for(i=0;str*i+!=\0;i++) count++; printf(length of string=%d,count); getch(); }
Output: enter string: computer length of string=8 or enter string: computer engineering length of string=8
18
11.Write a program to print length of string using gets(). #include<stdio.h> #include<conio.h> Void main() { int i,count=0; char str[50]; clrscr(); puts(enter string:); gets(str); for(i=0;str*i+!=\0;i++) count++; printf(length of string=%d,count); getch(); }
Output: enter string: computer length of string=8 or enter string: computer engineering length of string=15
19
12.Write a program to print reverse string without using strrev(). #include<stdio.h> #include<conio.h> Void main() { int i,j,len; char str[50],rev[50]; clrscr(); puts(enter string:); gets(str); for(len=0;str[len]!=NULL;len++) printf( ); for(i=len-1,j=0;i>=0;i--,j++) { rev[j]=str[i]; } rev[j]=NULL; printf(reverse string=%s\nrev); getch(); }
Output: enter string: computer reverse string=repupmoc
20
13.Write a program to check whether the given word is Palindrome or not.
#include<stdio.h> #include<conio.h> Void main() { char str[50],temp[50]; clrscr(); puts(enter word:); gets(str) strcpy(temp,str); strrev(temp); if(strcmp(str,temp)==0) printf(given number is palindrome\n); else printf(given number is not palindrome\n); getch(); } Output: enter word: madam given number is palindrome or enter word: computer given number is not palindrome
21
14. Write a program to convert lowercase characters of a string in uppercase.
Output: enter lowercase characters string: aij AIJ
22
14. Write a program which accept string from user and print its equivalent ASCII code. #include<stdio.h> #include<conio.h> #include<string.h> Void main() { char[50]; int i; clrscr(); puts(enter string:); gets(str); printf(ASCII code of %s is\n,str); for(i=0;i<strlen(str);i++) printf(%d\t,str*i+); getch(); }
Output: enter string: COMPUTER ASCII code of COMPUTER is 67 79 77 80 85 84 69 82
23
15. Write a program to arrange five words in order. #include<stdio.h> #include<conio.h> #include<string.h> Void main() { char s[5][50],temp[50]; int i,j; clrscr(); puts(enter five words:); for(i=0;i<5;i++) gets(s[i]); for(i=0;i<4;i++) { For(j=i+1;j<5;j++) { if(strcmp(s[i],s[j])>0) { strcpy(temp,s[i]); strcpy(s[i],s[j]); strcpy(s[j],temp); } } } puts(words in order data:->); for(i=0;i<5;i++) printf(%s\n); getch(); } Output: enter five words: maths chemistry physics biology programming in c
words in order data:-> biology chemistry 24
maths physics programming in c
25
16. Write a program to print C C P C P R C P R O C P R O G C P R O G R C P R O G R A C P R O G R A M C P R O G R A M M C P R O G R A M M I C P R O G R A M M I N C P R O G R A M M I N G C P R O G R A M M I N G C P R O G R A M M I N C P R O G R A M M I C P R O G R A M M C P R O G R A M C P R O G R A C P R O G R C P R O G C P R O C P R C P C
Output: C C P C P R C P R O C P R O G C P R O G R C P R O G R A C P R O G R A M C P R O G R A M M C P R O G R A M M I C P R O G R A M M I N C P R O G R A M M I N G C P R O G R A M M I N G C P R O G R A M M I N C P R O G R A M M I C P R O G R A M M C P R O G R A M C P R O G R A C P R O G R C P R O G C P R O C P R C P C
27
17. Write a program to print multiplication table of 1 to 5. #include<stdio.h> #include<conio.h> #define rows 5 #define cols 5 Void main() { int multi[rows][cols]; int i,j,r,c; clrscr(); printf( multiplication table:\n); for(j=1;j<=cols;j++) printf(%7d,j); printf(\n------------------------------------------\n); for(i=0;i<rows;i++){ r=i+1; printf(%2d|\n,r); for(j=1;j<cols;j++){ c=j; multi[i][j]=r*c; printf(%7d,multi*i+*j+); } Printf(\n); } getch(); }
18. Write a program to print ascii code of uppercase characters A to Z to lowercase characters a to z. #include<stdio.h> #include<conio.h> Void main() { char c; clrscr(); printf(\n\n); for(c=65;c<=122;c++) { if(c>90 && c<97) continue: printf(|%5d-%c,c,c); } Printf(\n); getch(); }
G U J A R A T T A R A J U G G U J A R A A R A J U G G U J A R R A J U G G U J A A J U G G U J J U G G U U G G G
31
20. Write a program to demostrate various string functions. #include<stdio.h> #include<conio.h> #include<string.h> Void main() { Char s1[50],s2[50],temp[50]; int len,n; clrscr(); printf(enter string:\n); gets(s1); len=strlen(s1); printf(length of %s is %d\n.s1,len); puts(------------------------------------------------------); strcpy(temp,s1); printf(copy of %s is %s \ns1,temp); puts(-------------------------------------------------------); strrev(temp); printf(reverse of %s is %s\n,s1,temp); puts(------------------------------------------------------); printf(enter any uppercase string:\n); gets(s1); strlwr(s1); printf(converted lowercase string is %s\n,s1); puts(----------------------------------------------------); printf(enter any lowercase string:\n); gets(s1); strupr(s1); printf(converted uppercase is %s\n,s1); puts(----------------------------------------------); printf(enter first string:\n); gets(s1); printf(enter second string:\n); gets(s2); strcat(s1,s2); printf(joined string is %s \n,s1); puts(-------------------------------------------); printf(enter first string:\n); scanf(%s,&s1); printf(enter second string:\n); scanf(%s,&s2); 32
printf(enter n:\n); scanf(%d,&n); strncat(s1,s2,n); printf(joined n character string is %s,s1,s2); puts(---------------------------------------------); printf(enter first string:\n); scanf(%s,&s1); printf(enter second string:\n); scanf(%s,&s2); if(strcmp(s1,s2)==0) printf(strings are same\n); else printf(strings are not same\n); puts(------------------------------------------------); printf(enter n:\n); scanf(%d,&n); if(strncmp(s1,s2,n)==0) printf(n characters of string are same\n); else printf(n characters of string are not same\n); getch(); }
Output:
Enter string: aij length of aij is 3 -------------------------------------------- Copy of aij is aij --------------------------------------------- Reverse of aij is jia --------------------------------------------- Enter any uppercase string: AIJ Converted lowercase string is aij ---------------------------------------------- Enter any lowercase string: aij converted uppercase string is AIJ ------------------------------------------------ Enter first string: 33
amrut enter second string: institute joined string is amrutinstitute -------------------------------------------------- Enter first string: amrut enter second string: institute enter n: 3 Joined n characters string is amrutins ---------------------------------------------------- Enter first string: amrut enter second string: amrut strings are same --------------------------------------------------- Enter n: 3 n characters of string are same
21. Write a program to demostrate use of function. #include<stdio.h> #include<conio.h> Void a() { int a; printf(enter a:); scanf(%d,&a); printf(a=%d,a); } Void main() { Clrscr(); a(); getch(); } Output: Enter a: 2 a=2 34
22. Write a program to demostrate function using no arguments and no return type.
#include<stdio.h> #include<conio.h> Void a(); Void main() { Clrscr(); a(); getch(); } Void a() { int num; printf(enter number:\n); scanf(%d,&num); if(num%2==0) printf(%d is even,num); else printf(%d is odd,num); } Output: Enter number: 4 4 is even
35
23. Write a program to demostrate function using no argument but return type. #include<stdio.h> #include<conio.h> int sum (); void main() { Clrscr(); Sum(); getch(); } int sum() { int a,b,sum; printf(enter two numbers:\n); scanf(%d %d,&a,&b); sum=a+b; printf(sum=%d,sum); return(sum); } Output: Enter two numbers: 3 2 Sum=5
36
24. Write a program to demostrate function with argument but no return type. #include<stdio.h> #include<conio.h> Void max(int,int); Void main() { int a,b; clrscr(); max(a,b); getch(); } Void max(int c,int d) { Printf(enter two integer numbers:\n); Scanf(%d %d,&c,&d); if(c>d) Printf(maximum number is %d,c); else printf(maximum number is %d,d); } Output: Enter two integer numbers: 2 3 Maximum number is 3
37
25. Write a program to demostrate function with argument and with return type. #include<stdio.h> #include<conio.h> #include<math.h> int fun(int,int); void main() { int a,s; clrscr(); fun(a,s); getch(); } int fun(int a,int s) { Printf(enter a:\n); Scanf(%d,&a); S=sqrt(a); Printf(squareroot of %d is %d,a,s); return (s); } Output: Enter a: 4 Squareroot of 4 is 2
38
26. Write a program to find factorial using recursive function. #include<stdio.h> #include<conio.h> int fact(int); void main() { int fc,n; clrscr(); puts(enter number:); scanf(%d,&n); fc=fact(n); printf(factorial=%d,fc); getch(); } int fact(int n){ int f=1; if(n==1) return(f); f=n*fact(n-1) return(f); } Output: Enter number: 5 factorial=120
39
27. Write a program to swap of two numbers using function.
#include<stdio.h> #include<conio.h> int swap(int,int,int); void main() { int n1,n2,n3; clrscr(); swap(n1,n2,n3); getch(); } int swap(int a,int b,int temp) { Printf(enter numbers:\n); Scanf(%d %d,&a,&b); Printf(numbers before swapping->\n); Printf(a=%d\nb=%d\n,a,b); temp=a; a=b; b=temp; printf(numbers after swapping->\n); printf(a=%d\nb=%d\n,a,b); return (a,b); }
Output: enter numbers: 2 3 numbers before swapping-> a=2 b=3 numbers after swapping-> a=3 b=2
40
28. Write a program to print array elements in ascending order data using function. #include<stdio.h> #include<conio.h> Void data(int [],int n); Void main() { int i,n,a[10]; clrscr() printf(enter n:\n); scanf(%d,&n); printf(enter array elements:\n); for(i=0;i<n;i++) { Scanf(%d,&a*i+); } data(a,n); printf(array elements in ascending order data->\n); for(i=0;i<n;i++) printf(%d\n,a*i+); getch(); } Void data(int a[],int n) { int i,j,temp; for(i=0;i<n-1;i++) { for(j=i+1;j<n;j++) { if(a[i]>a[j]) { temp=a[i]; a[i]=a[j]; a[j]=temp; } } } }
41
Output:
Enter n: 4 Enter array elements: 1 4 3 2 array elements in order data-> 1 2 3 4
29. Write a program to print factorial using function.
#include<stdio.h> #include<conio.h> int fact(); void main() { clrscr(); fact(); getch(); } int fact(){ int n,f=1,i=1; ` printf(enter number:\n); Scanf(%d,&n); for(i=1;i<=n;i++) { f=f*i; } Printf(factorial=%d,f); return(f); } Output: Enter n: 5 factorial=120
42
30. Write a program to generate Fibonacci series using recursive function. #include<stdio.h> #incude<conio.h> int Fibonacci(int); void main() { int c,i=0,n; clrscr(); printf(enter n:\n); scanf(%d,&n); printf(Fibonacci series is:\n); for(c=1;c<=n;c++) { Printf(%d\n,Fibonacci(i)); } getch(); } int Fibonacci(int n) { if(n==0) return 0; else if(n==1) return 1; else return(Fibonacci(n-1)+Fibonacci(n-2)); } Output: Enter n; 4 Fibonacci series is: 0 1 1 2
43
31. Write a program to print table of squares and cubes of 1 to 10 numbers. #include<stdio.h> #include<conio.h> Void table(); Void main() { int a,s,c,n; clrscr(); table(); getch(); } Void table() { int a=1,s,c,n; printf(enter n:\n); scanf(%d,&n); printf(-------------------------------------------\n); printf(|number\t|square\t|cube\t|\n); printf(--------------------------------------------\n); while(a<=n) { Printf(|%d\t|,a); s=a*a; printf(%d\t|,s); c=s*a; printf(%d\t|\n,c); a++; } Printf(------------------------------------------\n); }
32. Write a program to pass one-dimensional array in function. #include<stdio.h> #include<conio.h> Void array(int [],int n); Void main() { int a[10],n,i; clrscr(); array(a,n); getch(); } Void array(int a[10],int n) { int i; printf(enter n:\n); scanf(%d,&n); printf(enter array elements :\n); for(i=0;i<n;i++) { Scanf(%d,&a*i+); } Printf(array elements location is:\n); for(i=0;i<n;i++){ Printf(a*%d+=%d\n,i,a*i+); } } Output: Enter n: 5 Enter array elements: 1 2 3 4 5 array elements location is: a[0]=1 a[1]=2 a[2]=3 a[3]=4 a[4]=5 46
33. Write a program to demostrate concept of local variable. #include<stdio.h> #include<conio.h> Void f(); Void main() { int a; // local variable in main() clrscr(); printf(enter a:\n); scanf(%d,&a); printf(a=%d\n,a); f(); getch(); } Void f() { int a; // local variable in UDF printf(enter a:\n); scanf(%d,&a); printf(a=%d,a); }
Output:
Enter a: 2 a=2 enter a: 5 a=5
47
34. Write a program to demostrate concept of global variable. #include<stdio.h> #include<conio.h> int x,y; // global variables void f(int); void main(){ int max; clrscr(); printf(enter x & y:\n); scanf(%d %d,&x,&y); f(max); getch(); } Void f(int max){ if(x>y) max=x; else max=y; printf(max=%d,max); } Output: Enter x & y: 3 2 Max=3
48
35. Write a program to demostrate concept of static variables.
#include<stdio.h> #include<conio.h> Static int x,y; // static global Void f(); Void main(){ int min; clrscr(); printf(enter x & y:\n); scanf(%d %d,&x,&y); f(); getch(); } Void f(){ Static int min; // static local If(x<y) min=x; else min=y; printf(min=%d,min); }
Output:
Enter x & y: 3 2 min=2
49
35.Write a program to demo call by value.
#include<stdio.h> #include<conio.h> int f(int); void main() { int a; clrscr(); a=f(2); printf(a=%d,a); getch(); } int f(int a) { a=2; return a; }
Output: a=2
50
36. Write a program to check whether a word is palindrome or not using function. #include<stdio.h> #include<conio.h> #include<string.h> Void pal(char []) { char str[50],temp[50]; clrscr(); puts(enter a string:); gets(str); pal(str); getch(); } Void pal(char str[50]) { Char temp[50]; Strcpy(temp,str); Strrev(temp); if(strcmp(str,temp)==0) printf(given word is palindrome); else printf(given word is not palindrome); }
Output: Enter a string: madam given word is palindrome or enter a string: apple given word is not palindrome
51
37. Write a program to check whether a given number is prime or not. #include<stdio.h> #include<conio.h> int prime(int); void main() { int n,i; clrscr(); printf(enter number:\n); scanf(%d,&n); prime(n); getch(); } int prime(int n) { int i; for(i=2;i<=n;i++) if(n%i==0) { Printf(number is not prime); return 1; } else { printf(number is prime); return 0; } }
Output:
Enter number: 19 Number is prime Or Enter number: 46 Number is not prime
52
38. Write a program to print largest word from given string. #include<stdio.h> #include<conio.h> Void word(int); Void main() { int n; clrscr(); word(n); getch(); } Void word(int n) { char str[10][10]; int i,max,len[10]; printf(enter n:\n); scanf(%d,&n); printf(enter string:\n); for(i=0;i<n;i++) { gets(str[i]); } for(i=0;i<n;i++) { len[i]=strlen(str[i]); } max=len[10]; for(i=1;i<n;i++) { if(max<len[i]) { max=len[i]; } } Printf(maximum length=%d\n,max); for(i=0;i<n;i++) { if(strlen(str[i])==max) { Printf(largetst word is %s,str*i+); } 53
} }
Output:
Enter n: 5 apple banana grapes pineapple onion maximum length=9 largest word is pineapple
54
39. Write a program to print reverse string using recursive function. #include<stdio.h> #include<conio.h> Void reverse(char []); Void main() { Char s[10]; Clrscr(); puts(enter string:); gets(s); puts(reverse string is); reverse(s); getch(); } Void reverse(char s[10]) { int i=0; if(s[i+1]!=NULL) reverse(&s[i+1]); putchar(s[i]); } Output: Enter string: Computer reverse string is retupmoc
55
40. Write a program to demonstrate use of typedef data type.
#include<stdio.h> #include<conio.h> Void main() { typedef int a; a s; clrscr(); printf(enter s:\n); scanf(%d,&s); printf(s=%d,s); getch(); }
Output:
Enter s:10 S=10
56
41. Write a program to demonstrate use of enumerated data type. #include<stdio.h> #include<conio.h> Void main() { enum month{jan=1,feb,mar,apr,may,jun,jul,aug,sep,oct,nov,dec}; enum month m; clrscr(); printf(enter month number:\n); scanf(%d,&m); printf(month name=); switch(m) { Case 1:printf(January\n); break; Case 2:printf(february\n); break; Case 3:printf(march\n); break; Case 4:printf(april\n); break; Case 5:printf(may\n); break; Case 6:printf(june\n); break; Case 7:printf(July\n); break; Case 8:printf(august\n); break; Case 9:printf(september\n); break; Case 10:printf(october\n); break; Case 11:printf(november\n); break; Case 12:printf(december\n); break; default:printf(wrong input\n); break; } getch(); 57
}
Output:
Enter month number: 3 March
58
42. Write a program to demonstrate use of structure.
Output: Enter student en_no and name: 1 abc 2 def 3 xyz your data is-> enroll number=1 name=abc enroll number=2 name=def enroll number=3 name=xyz
61
45. Write a program to input details of four students and display marksheet. #include<stdio.h> #include<conio.h> struct student { int en_no; char name[50]; int marks[3]; int total; }; void main() { struct student s[3],temp; int i,j; clrscr(); for(i=0;i<3;i++) { Printf(enter en_no:\n); scanf("%d",&s[i].en_no); printf(enter name:\n); scanf("%s",&s[i].name); printf("enter marks of three subjects:\n"); scanf("%d %d %d",&s[i].marks[0],&s[i].marks[1],&s[i].marks[2]); s[i].total=s[i].marks[0]+s[i].marks[1]+s[i].marks[2]; } printf("marksheet->\n"); printf("en_no\tname\tsub1\tsub2\tsub3\ttotal\tper\n"); for(i=0;i<3;i++) { printf("%d\t",s[i].en_no); printf("%s\t",s[i].name); printf("%d\t",s[i].marks[0]); printf("%d\t",s[i].marks[1]); printf("%d\t",s[i].marks[2]); printf("%d\t",s[i].total); } getch(); }
62
Output:
Enter en_no : 1 Enter name: abc Enter marks of three subjects: 12 34 45 Enter en_no: 2 Enter name: def Enter marks of three subjects: 45 67 78 Enter en_no: 3 Enter name: xyz Enter marks of three subjects: 67 89 70
46. Write a program to display merit list of students using structure. #include<stdio.h> #include<conio.h> struct merit { int en_no; char name[50]; int marks[3]; int total; float per; }; void main() { struct merit s[5],temp; int i,j; clrscr(); printf(enter five students en_no,name and marks of three subjects:\n); for(i=0;i<5;i++) { scanf("%d",&s[i].en_no); scanf("%s",&s[i].name); scanf("%d %d %d",&s[i].marks[0],&s[i].marks[1],&s[i].marks[2]); s[i].total=s[i].marks[0]+s[i].marks[1]+s[i].marks[2]; s[i].per=(s[i].total/3); } for(i=0;i<4;i++) { for(j=i+1;j<5;j++) { if(s[i].total<s[j].total) { temp=s[i]; s[i]=s[j]; s[j]=temp; } } } printf("marit list->\n"); printf("en_no\tname\tsub1\tsub2\tsub3\ttotal\tper\n"); for(i=0;i<5;i++) { 64
Enter five students en_no,name and marks of three subjects: 1 abc 12 23 34 2 def 34 45 56 3 xyz 56 67 78 4 jkl 67 76 57 5 ghi 99 90 95 Marit list-> En_no name s1 s2 s3 total per 5 abc 99 90 95 284 94.00 3 xyz 56 67 78 201 67.00 4 jkl 67 76 57 200 66.00 2 def 34 45 56 135 45.00 1 abc 12 23 34 69 23.00
65
47. Write a program to details & search a record as ecode,name and salary. #include<stdio.h> #include<conio.h> struct empoyee { char ename[50]; int ecode; int esalary; }s[3]; void main() { int i,flag=0,code; clrscr(); printf("enter name,ecode and salary of three employees:\n"); for(i=0;i<3;i++) { scanf("%s %d %d",&s[i].ename,&s[i].ecode,&s[i].esalary); } printf("enter code of employee:\n"); scanf("%d",&code); for(i=0;i<3;i++) { if(s[i].ecode==code) { flag=1; printf("name=%s\n",s[i].ename); printf("ecode=%d\n",s[i].ecode); printf("salary=%d\n",s[i].esalary); goto outer; } } outer: if(!flag) { printf("data not found\n"); } getch(); }
66
Output:
Enter name,ecode and salary of three employees: abc 123 5000 def 345 10000 xyz 567 3000 enter code of employee: 345 name=def ecode=345 salary=10000
or
Enter name,ecode and salary of three employees: abc 123 5000 def 345 10000 xyz 567 3000 enter code of employee: 789 data not found
67
48. Write a program to input five account holders of a bank and deposited or withdraw money as per selection using structure. #include<stdio.h> #include<conio.h> void credit(int); void dabit(int); struct holders { int accountno; char h_name[50]; int balance; int ammount; }h[5];
void main() { char n; int i,a,flag=0,k; clrscr(); printf("enter holder's name,account number and bank balance\n"); for(i=0;i<5;i++) { scanf("%s %d %d",&h[i].h_name,&h[i].accountno,&h[i].balance); } printf("enter ac no.\n"); scanf("%d",&a); for(i=0;i<5;i++) { if(a==h[i].accountno) { flag=1; k=i; printf("your data is->\n"); printf("holder's name=%s\n",h[i].h_name); printf("account no.=%d\n",h[i].accountno); printf("bank balance=%d\n",h[i].balance); goto outer; } } outer: if(!flag) 68
{ printf("data not found"); } printf("enter your choice d/D or c/C:\n"); scanf("%s",&n);
if(n=='d' || n=='D')
dabit(k);
else
credit(k);
getch(); } void dabit(int k) { int i; printf("enter ammount:\n"); scanf("%d",&h[k].ammount); if(h[k].ammount>h[k].balance) { printf("you don't have enough balance in your account"); } else { h[k].balance=h[k].balance-h[k].ammount; printf("your new balance is %d\n",h[k].balance); }
}
void credit(int k) { int i; printf("enter ammount:\n"); scanf("%d",&h[k].ammount); 69
h[k].balance=h[k].balance+h[k].ammount; printf("your new balance is %d\n",h[k].balance);
}
Output:
Enter holders name,account number and bank balance: abc 123 5000 def 456 10000 ghi 678 4000 jkl 789 5900 mno 453 6000 enter ac no: 123 Your data is-> holders name=abc account number=123 bank balance=5000 enter your choice d/D or c/C: d enter amount: 2000 Your new balance is 3000 or Enter holders name,account number and bank balance: abc 123 5000 def 456 10000 ghi 678 4000 jkl 789 5900 mno 453 6000 enter ac no: 123 Your data is-> holders name=abc account number=123 bank balance=5000 enter your choice d/D or c/C: c enter amount: 4000 Your new balance is 9000 70
48. Write a program to check how to use union.
#include<stdio.h> #include<conio.h> void word(int); union student { int en_no; char name[50]; }s; Void main() { int i; Clrscr(); Printf(enter en_no:\n); Scanf(%d,&s.en_no); printf(enroll number=%d\n,s.en_no); Printf(enter name:\n); gets(s.name); printf(name=%s\n,s.name); i=sizeof(s); printf(size of union=%d\n,i); getch(); }
Output:
Enter en_no: 1 enroll number=1 Enter name: abc name=abc size of union=50
71
49.Write a program to demonstrate union within structure.
#include<stdio.h> #include<conio.h> struct student { int en_no; char name[50]; union collage { char c_name[100]; char branch[50]; }c; }s; void main() { int i,u; clrscr(); printf("enter en_no:\n"); scanf("%d",&s.en_no); printf("enter name:\n"); scanf("%s",&s.name); printf("en_no=%d\n",s.en_no); printf("student name=%s\n",s.name); printf("enter branch name:\n"); scanf("%s",&s.c.branch); printf("branch name=%s\n",s.c.branch); printf("enter college name:\n"); scanf("%s",&s.c.c_name); printf("college name=%s\n",s.c.c_name); i=sizeof(s); printf("size of structure=%d\n",i); u=sizeof(s.c); printf("size of union=%d\n",u); getch(); }
Output: Enter en_no: 1 Enter name: abc 72
en_no=1 student name=abc enter branch name: computer branch name=computer enter college name: aij college name=aij size of structure=152 size of union=100
50. Write a program to demonstrate simple macro using #define.
#include<stdio.h> #include<conio.h> #define pie 3.14 Void main() { int r; float area; clrscr(); printf(enter r:\n); scanf(%d,&r); area=pie*r*r; printf(area of circle=%f\n,area); getch(); }
Output: Enter r: 2 area of circle=12.56
73
51. Write a program to demonstrate use of macro with argument.
Output: Enter string: Raman age 25,aij! alpha=11 digits=2 space=2 punct=2 75
54. Write a program to demonstrate nested macros.
#include<stdio.h> #include<conio.h> #define pie 3.14 #define area(r) pie*r*r #define volume(r) (4*area(r)*r)/3 void main() { int r; clrscr(); printf("enter radius:\n"); scanf("%d",&r); printf("area of circle=%f\n",area(r)); printf("volume of circle=%f\n",volume(r)); getch(); }
Output: Enter radius: 2 area of circle=12.56 volume of circle=33.493333
76
55. Write a program to display value and address of variable without using pointer.
#include<stdio.h> #include<conio.h> void main() { int a; clrscr(); printf("enter a:\n"); scanf("%d",&a); printf("value of a=%d\n",a); printf("address of a=%x\n",&a); getch(); }
Output: Enter a: 10 Value of a=10 address of a=fff4
56. Write a program to display value and address of variable using pointer.
#include<stdio.h> #include<conio.h> void main() { int a=2; int *p; clrscr(); p=&a; printf("value of a=%d\n",a); printf("value of pointer=%x\n",p); getch(); }
Output: Value of a=2 Value of pointer=fff4
77
57. Write a program to increment value of variable using pointer variable.
#include<stdio.h> #include<conio.h> void main() { int a; int *p; clrscr(); printf("enter a:\n"); scanf("%d",&a); p=&a; printf("data before using pointer->\n"); printf("name\tvalue\taddress\n"); printf("a\t%d\t%x\n",a,&a); printf("data after using pointer->\n"); printf("a\t%d\t%x\n",*p,p); printf("data after increment->\n"); *p=*p+1; printf("a\t%d\t%x\n",*p,p); getch(); }
Output: Enter a: 2 Data before using pointer-> Name value address a 2 fff4 data after using pointer-> a 2 fff4 data after increment-> a 3 fff4
78
58. Write a program to
#include<stdio.h> #include<conio.h> void main() {
int a=10; int *p; int *q; clrscr(); p=&a; q=p; printf("value of variable=%d\n",*q); printf("address of variable=%x\n",q); printf("value of pointer=%x\n",q); getch(); }
Output: Value of variable=10 address of variable=fff4 value of pointer=fff4
79
59. Write a program to print value and address of pointer.
#include<stdio.h> #include<conio.h> void main() { int *p; int a=10; clrscr(); p=&a; printf("value of variable=%d\n",*p); printf("address of variable=%x\n",p); printf("value of pointer=%x\n",p); printf("address of pointer=%x\n",&p); getch(); }
Output: value of variable=10 address of variable=fff2 value of pointer=fff2 address of pointer=fff4