Computer Science, asked by asthavaghe, 7 months ago

Write a program to print factorial of a given number using function.​

Answers

Answered by manas3333
2

Explanation:

include <stdio.h>

int fact(int);

void main() {

int no,factorial;

printf("Enter a number to calculate it's factorial\n"); scanf("%d",&no);

factorial=fact(no); ...

//printf("Factorial of the num(%d) = %d\n",no,fact(no));//another way of calling a function//comment above two lines if you want to use this. ...

int fact(int n)

Answered by aryaman7839
3

#include <stdio.h>

int main() {

int n, i;

unsigned long long fact = 1;

printf("Enter an integer: ");

scanf("%d", &n);

// shows error if the user enters a negative integer

if (n < 0)

printf("Error! Factorial of a negative number doesn't exist.");

else {

for (i = 1; i <= n; ++i) {

fact *= i;

}

printf("Factorial of %d = %llu", n, fact);

}

return 0;

}

Similar questions