C programming 2014
year 2014 Q.no 3 Write function that display the factorial of 7 only.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
#include<stdio.h> void fact(int n) { int fact = 1; if(n==7) { for(int i=1;i<=n;i++) fact*=i; printf("The factorial of 7 is: %d.",fact); } else printf("This function gives the factorial of the number 7 only"); } void main() { fact(7); } Output: The factorial of 7 is: 5040. |
Q.no 4 Write program that takes string as input from the user, and then display the length.
1 2 3 4 5 6 7 8 9 |
#include<stdio.h> #include<string.h> void main() { char srt[50]; printf("Enter a string:\n"); gets(str); printf("The length of string is %d.",strlen(srt)); } |
Q.no 5 Write a program to display the following pattern. * # * # * ? ? * ? ? +
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
#include<stdio.h> void main() { int i; for(i=0;i<4;i++) { printf("*\t"); if(i<2) printf("#"); if(i==2) printf("?\t?"); if(i==3) printf("?\t?\t+"); printf("\n"); } } |
Group […]
Continue Reading