C programming 2016
2016 2. Display the following pattern using loop. a. BBA b. BIM c. BIM d. BBA e. BBA f. BIM
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
#include<stdio.h> void main() { int i; char c='a'; for(i=1;i<=6;i++) { if(i==1||i==4||i==5) printf("%c. BBA\n",c); else printf("%c. BIM\n",c); c++; } } |
3. Write a program to count white spaces in a given sentence.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
#include<stdio.h> #include<string.h> void main() { char s[100]; int i=0,c=0,l=0; printf("Enter a string:\n"); gets(s); while(s[i]!='\0') { l++; i++; } for(i=0;i<l;i++) { if(s[i]==' ') c++; } printf("Total number of white spaces in the given sentence is: %d.",c); } Output: Enter a string: Hello My Name is Total number of white spaces in the given sentence is: 3. |
4. Write a program to calculate the sum of the following numbers: -3, -4, 8, 9, 10, -17.
1 2 3 4 5 6 7 8 9 10 |
#include<stdio.h> void main() { int a[6]={(-3),(-4),8,9,10,(-17)}; int i,sum=0; for(i=0;i<6;i++) { sum+=a[i]; } printf("The sum of (-3,-4,8,9,10,-17) is %d",sum); } |
5. Write […]
Continue Reading