Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

edlingT Heading2 Heading 3 Title Subtle Em... . Emphasis Intense E Styles Using

ID: 3872013 • Letter: E

Question

edlingT Heading2 Heading 3 Title Subtle Em... . Emphasis Intense E Styles Using the for Looping (Repetition) Structure design a program that prompts the user to enter a positive integer number. Use a for loop to calculate and display the factorial value of that number. A factorial number is a number multiplied by every factor between 1 and the number, inclusive. For instance, 3 factorial is 3 2 *1. If the user enters negative number, display a message indicating that the program calculates only positive numbers. Otherwise, display the result of the calculation. // Enter,your name as a comment for program identification II Program assignment Factorial.cpp // Enter your class section, and time /* The program Factorial1.cpp is a program that prompts the user to enter a positive integer number The program will then use a for loop to calculate and display the factorial value of that number. This in the for loop. A factorial number is a number multiplied by every factor between 1 and the number inclusive. For instance 3 factorial is 3·2·1. if the user enters a negative number, display a message indicating that the program cakculates only positive numbers. Otherwise, display the result of the calculation. The input is a positive integer number. The factorial value of the numbe er entered or a message indicating that the number is not positive. // header files use the correct preprocessor directives for input/output // declare variables /- declare an integer variable number to input a value and a integer variable factorial initialized to 1 to calculate the factorial value of the number entered

Explanation / Answer

// name

//factorial.cpp

//section

#include <iostream>

using namespace std;

int main() {

int num,fact,i;

fact = 1;

//input the num

cout<<"Enter a positive integer number : ";

cin>>num;

if(num < 0) // num is not positive

cout<<" The number entered is not positive."; //error message

else if( num < 1)

cout<<" The factorial of numbers greater than or equal to 1 are calculated";

else

{

//for loop to compute factorial of num

for(i=num;i>=1;i--)

{

fact = fact * i;

}

//display output

cout<<" The factorial of "<<num <<" is "<<fact;

}

return 0;

}

Output:

Variable name data type value in memory line number at declaration line number when initialized i int 1 10 27 num int 7 10 16 factorial int 5040 10 12