Question #269307

c++ program to find the factorial of any number between 3 and 9

Expert's answer

#include<iostream>
using namespace std;
int main(){
	cout<<"Enter a number between 3 and 9\n";
	int n;
	cin>>n;
		int fact =1;
	switch(n){
		case 3 ... 9:
		
			for(int i=1; i<=n; i++){
				fact *= i;
			}
			cout<<"The factorial of "<<n<<"  is "<<fact<<endl;
			break;
		default:
			cout<<"The number should be between 3 and 9 "<<endl;
	}
	
}
LATEST TUTORIALS
APPROVED BY CLIENTS