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;
}
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;
}
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.
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.
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;
}
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; }
Oopss sorry new to this place ..
I wanted to print 1*2*3*4...
for the for loop not just the answer
Ya.. now your program must works fine ..
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.