for example 1*2*3*4*5*6

this is what i have:

#include <iostream>

using namespace std;

int main(){
	  

int num =1;
int i; 

for (i=1; i <=20; i++)
{
    num *=i;
    cout<<num<< " * ";
}

system("pause");
	return 0;
}

Edited 6 Years Ago by Transcendent: n/a

It is i that you should cout << not num
at least inside the loop
you can cout << " = " << num
after the loop

Whats your error???
Answer not correct?

Use a larger data type ..
instead of

int num=1;

try

long num=1;

or

long long num=1;

it did work man. can you write it.

Are you joking? It's 2 extremely simple changes.

Change num to i inside the loop then add another output line. It's not that hard.

Edited 6 Years Ago by Fbody: n/a

He mean ..

#include <iostream>
using namespace std;

int main(){
long long num =1;
int i; 

for (i=1; i <=20; i++)
{
    num *=i;
    cout<< i << " * ";
}

cout << "=" << num << endl ;
system("pause");
	return 0;
}
Comments
Not mean. I actually follow the forum rules.
This article has been dead for over six months. Start a new discussion instead.