C-User Defined Function Codes ( 24 Questions Solved)
1. Write a program to find the factorial of a given number using function. #include<stdio.h> long factorial(int a); int main() { int n; long Fact; printf("Enter the number:"); scanf("%d",&n); Fact=factorial(n); printf("The factorial of the %d is %ld",n,Fact); } long factorial(int a) { int i; long fact=1; for(i=1; i<=a; i++) { fact=fact*i; } return fact; } 2. Write a program to find the combination using function #include<stdio.h> long factorial(int); int main() { int n,r; long f1,f2,f3,C; printf("Enter the total number,n and number being chosen,r:"); scanf("%d%d",&n,&r); f1=factorial(n); f2=factorial(n-r); f3=factorial(r); C=f1/(f2*f3); printf("The combination is %ld",C); return 0; } long factorial(int n) { int i; long Fact=1; for(i=1; i<=n; i++) { Fact=Fact*i; } return Fact; } 3. Write a program to find the s...