LOOPING STATEMENTS AND FUNCTIONS
Create a flowchart to guide you in the process
Create a function that will accept the value of i and return the value of n
Possible values of i is any positive value from 2 to 10
n is computed based on the value of i; see the following table for the sample Input / Output
!!Please see these 3 examples on how the screen will work when the program runs!!
1.)
i : 3
Process: 1*2*3
n: 6
2.)
i: 5
Process: 1*2*3*4*5
n: 120
3.)
i: 7
Process: 1*2*3*4*5*6*7
n: 5040
Screen/Layout
(Home Screen)
Input i:3
Process: 1*2*3
Output: 6
Try Another [Y/N]: Y
Input i: 5
Process: 1*2*3*4*5
Output: 120
Try Another [Y/N]: Y
#include<iostream>
#include<string>
using namespace std;
int main(){
int i;
cin>>i;
int factorial = 1;
string results = " ";
cout<<"Process: ";
for(int x=1; x<=i; x++){
factorial *= x;
results += to_string(x) + "*";
}
cout<<results<<endl;
cout<<"n: "<<factorial<<endl;
}
Comments
Leave a comment