Factorial Program

The Program doesn't work properly

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
  //factorial program which takes integer n and prints its factorial
//and the operation repeats until n<=0
#include <iostream>
using namespace std;

int main()
{
  int num,factorial=1;


while (1)
{
        cin>>num;

      if(num<=0)
        return 0;
      else

        for(int i=2;i<=num;i++)
  {
      factorial*=i;


  }
  cout<<factorial<<endl;





}
return 0;

}
Describe your problem better. Reset factorial to 1 when you start the while loop again.
Last edited on
The Problem is :Write a c++ Program which takes an integer number n and prints its factorial.You should repeat this operation until n<=0
and thank you for reply
Topic archived. No new replies allowed.