In main() you will still prompt the user for a positive integer, n, but then you will pass it to a function that calculates n! and then returns the value to main() for printing.Code:#include <stdio.h> int main(void) { int n, i, sum; printf("Enter a value for n!: "); scanf("%d", &n); sum = n; for( i = 1; i < n; i++ ) sum = sum * ( n - i ); printf("n! is %d\n", sum); }
How do I change this into a function?