Breaking News

C++ Program To Find Factorial

This program is used to find factorial of n numbers.

Algorithm:

1.Start
2.Get the input from user for variable n (ie) an integer number
3.Initialize fact as 1
4.You will need a for loop to find factorial of given number
5.In for loop set i as 1 then compare if i is lesser than or equal to zero
6.If step-5 is true declare fact as fact * i and if step-5 is false stop the program
7.Increment i value by 1
8.Stop




Program:

# include <iostream.h>
# include <conio.h>
void main ()
{
           clrscr();
          int n, fact = 1;
          cout << "Enter Value For N:";
          cin >> n;
          for (int i = 1; i <= n; i + +)
          {
                    fact = fact * i;
           }
           cout << "The Factorial Of" << n << "Is:" << fact;
           getch ();
}

No comments