Answer to Question #258030 in C for Sam

Question #258030
Write a program that takes or prompt an int. and return it as it is. Example: 5 to return 5 Calculate the factorial and the factorial..
1
Expert's answer
2021-10-29T00:54:57-0400


#include <stdio.h>
int getData(){
    int n;
    printf("\nEnter a number: ");
    scanf("%d",&n);
    return n;
}
void factorial(){
    int x=getData();
    int fact=1;
    if (x==1)
        printf("\nFactorial of %d = 1",x);
    else{
        for(int i=1;i<=x;i++){
            fact=fact*i;
        }
        printf("\nFactorial of %d = %d",x,fact);
    }
}
int main()
{
    factorial();


    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS