In: Computer Science
compute and print factorial if it is equal to 6,
not equal to 6,
and square of the factorial, if the input is equal to 6 ..... C programming
#include <stdio.h>
int factorial(int a); //function prototype to calculate
factorial
int main(int argc, char *argv[]) {
int a,b;
printf("Enter input:\n");
scanf("%d",&a); //stores the input
b=factorial(a); //calculate factorial of input
printf("Factorial of %d is %d\n",a,b); //display factorial
if(a==6){
printf("Square of factorial of %d is %d\n",a,b*b);
//if input is 6 then display square of factorial also
}
return 0;
}
//function to calculate factorial
int factorial(int a){
if(a==0){
return 1;
}else{
return a*factorial(a-1);
}
}