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>
using namespace std;
int main(){
int i;
cin>>i;
cout<<"Process = ";
int fact = 1;
int n = 1;
for(int x=i; x>=1; x--){
fact *= x;
cout<<n <<"*";
n++;
}
cout<<"\nn: "<<fact<<endl;
}
Comments
Leave a comment