Question #15339

write a program that will compute n! (factorial) which is the product of all number from1 to n.

Expert's answer

#include<iostream.h>

int factorial(int n){

int res=1;

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

& res = res*i;

return res;

}

void main(){

int m;

cout<<"Enter an integer: ";

cin>>m;

cout<<factorial(m)<<"\n";

}

int factorial(int n){

int res=1;

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

& res = res*i;

return res;

}

void main(){

int m;

cout<<"Enter an integer: ";

cin>>m;

cout<<factorial(m)<<"\n";

}

## Comments

## Leave a comment