Problem Statement You s to reate a program that will allo th

Problem Statement: You s to reate a program that will allo the user to determine th largest integer such that ! n factoria that an be computed on the computer that the program s being run Here e g 23-6 41-24 etc The program should prompt the user to input an integer n, calculate and display the value of n, and then ask the user to input another value. The program terminates when the user enters a value of-1 for n. Using the program, you should be able to discover the largest value of n such that n! can be correctly calculated on your computer Grading: 20% Proper comments and variable definition 10% submitted on time 70% Code compiles and gives the correct result

Solution

#include<iostream>
using namespace std;
int main(){
//declare n to store input from user
int n;
//long integer to store factorial value
long long fact;
while(true){
//initial factorial value is set to 1
fact = 1;
  
// get user input
cout << \"Enter a number:\";
cin >> n;
  
//if input is -1 break loop
if(n==-1){
break;
}
  
//calculate factorial by mutliplying f with n and reducing n by 1.
while(n>0){
fact *= n;
n--;
}
//printing output
cout << \"factorial value is \" << fact << endl;
}
}

/*
sample outputs
Enter a number: 20
factorial value is 2432902008176640000
Enter a number: 25
factorial value is 7034535277573963776
Enter a number: -1
*/


Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site