Create C++ full program that calculates a factorial (!) of any number between 3 and 9; the
program should give feedback to the user if the number is less than 3(error number is less than 3), the program should also give feedback if number is greater than 9; you can use either the case or else statement also while loop if applicable
#include<iostream>
using namespace std;
int val(int n){
int r = 0;
if(n<3){
cout<<"The number is less than 3\n";
r = 1;
}
else if(n>9){
cout<<"The number is greater than 9\n";
r = 1;
}
else{
r = 0;
}
return r;
}
int main(){
cout<<"Enter a number: ";
int n;
cin>>n;
if(val(n)==0){
int fact = 1;
for(int i=1; i<=n; i++){
fact *= i;
}
cout<<"Factorial of "<<n<<" is "<<fact<<endl;
}
}
Comments
Leave a comment