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 a function to check if the entered prime number is greater than 90 and is odd.
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 |
#include <stdio.h> int main() { int n, i, flag = 0; printf("Enter a prime number: "); scanf("%d",&n); for(i=2; i<=n/2; i++) { if(n%i==0) { flag=1; break; } } if (flag==0) { printf("%d is a prime number ",n); if (n>90) printf(" is greater than 90 "); else printf(" is greater than 90 "); if(n%2!=0) printf(" and is odd "); else printf(" and is even "); } else printf("%d is not a prime number",n) ; return 0; } |
6. Write a function that converts the lowercase string into uppercase string.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
#include<stdio.h> #include<string.h> char *convert(char a[]) { return strupr(a); } void main() { char a[50]; printf("Enter a string(in lowercase): "); gets(a); printf("Given string in uppercase: %s",convert(a)); } Output: Enter a string(in lowercase): Hello Given string in uppercase: HELLO |
Group “C”
9. Write the output generated by the following program.
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 |
#include<stdio.h> #include<conio.h> void main(){ int a,b,c; clrscr(); for(a=1;a<=3;a++){ for(b=1;b<=3;b++){ for(c=1;c<=3;c++){ if(a==b||b==c||a==c){ continue; } else{ { printf("%d%d%d\n",a,b,c); } } } } } getch(); } Output: 123 132 213 231 312 321 |