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

LAB 6 B option: (The best grade is a 90%) Write a program that will calculate th

ID: 3606609 • Letter: L

Question

LAB 6

B option: (The best grade is a 90%) Write a program that will calculate the factorial of number Example: the factorial of 5 is 5 * 4*3* 2* 1120 en.wikipedia.org/wiki/Factorial .Input the starting number in mainO . Pass the number to a function called factorial(0 to calculate the Factorial number Prototype: In the function double factorial (double num); Use a for loop to calculate the answer Use a return statement to return the answer back to the caller . . Back in main, ask the user if they want to another enter number. (Use a loop in main)) A option: (The best grade is a 100%) Create a function called yesno0 . Keep looping until they enter y, Y, n, or N Prototype: int yesno0; . yesno0 should have a while loop in it. . If the user enters y, or Y return 1 If the user enters n or N return 0 Call this function when you need a yes or a no response Example of using vesno from main . 0 l/ lots of code } while (yesno(,-= 1 ); Turn in Program listing of your source code and screen prints of the following B option: A option: yesno) function so I can see it work correctly Submit a screen print of the factorial of 12 Submit some screen shots, including showing the factorial of 12, that exercise your

Explanation / Answer

Code1:

#include <iostream>
using namespace std;

int main()
{
unsigned int n;
unsigned long long factorial = 1;

cout << "Enter a positive integer: ";
cin >> n;

for(int i = 1; i <=n; ++i)
{
factorial *= i;
}

cout << "Factorial of " << n << " is " << factorial;   
return 0;
}

Output:

Code2:

#include <iostream>
using namespace std;

int main() {
int n, i = 1, fact = 1;

cout << "Enter a positive integer: ";
cin >> n;
  
while ( i <= n) {
fact *= i;   
++i;
}

cout<<"Factorial of "<< n <<" is "<< fact;
return 0;
}

Output: