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

Write a C++ program that determines the largest number for which your computer c

ID: 3768025 • Letter: W

Question

Write a C++ program that determines the largest number for which your computer can represent its factorial exactly using the longdouble type. A factorial is the product of all numbers from 1 to the given number. For example, 10 factorial (written 10!) is 1 times 2 times 3 times 4 times 5 times 6 times 7 times 8 times 9 times 10 = 3,628,800 As you can see, the factorial grows to be a large number very quickly. Your program should keep multiplying the prior factorial by the next integer, then subtract 1 and check whether the difference between the factorial and the factorial minus 1 is less than 1-an error tolerance. When the maximum precision of the type is reached, and least significant digits are truncated to allow the most significant digits of the product to be stored, then subtracting 1 should have no effect on the value. Because floating-point representations may not be exact, however, the expression

Explanation / Answer

#include<iostream.h>

#include<conio.h>

void main()

{

    int f, n;

    clrscr();

    cout<<" Enter a Number:";

    cin>>n;

    f=1;

    for(int i=1;i<=n;i++)

        f=f*i;

    cout<<" Factorial of "<<n<<" is "<<f;

    getch();

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote