# Answer to Question #23785 in C++ for EMMANUEL

Question #23785

write a program which inputs an integer value , checks that it is positive, and outputs its factorial, using the formulas:

factorial(0) = 1

factorial(n) = n * factorial(n-1)

factorial(0) = 1

factorial(n) = n * factorial(n-1)

Expert's answer

#include <iostream>

int factorial(int n){

int res=1;

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

& res = res*i;

return res;

}

bool positive(int n){

if (n>=0) { std::cout<<"positive\n"; return true; }

else { std::cout<<"negative\n"; return false; }

}

void main(){

int m;

std::cout<<"Enter an integer: ";

std::cin>>m;

if (positive(m)) std::cout<<factorial(m)<<"\n";

system("pause");

}

int factorial(int n){

int res=1;

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

& res = res*i;

return res;

}

bool positive(int n){

if (n>=0) { std::cout<<"positive\n"; return true; }

else { std::cout<<"negative\n"; return false; }

}

void main(){

int m;

std::cout<<"Enter an integer: ";

std::cin>>m;

if (positive(m)) std::cout<<factorial(m)<<"\n";

system("pause");

}

Need a fast expert's response?

Submit orderand get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

## Comments

## Leave a comment