couldnt work out!!!!
Mar 24, 2009 at 4:15pm UTC
Hi
i been trying to write program to write like this
1 2 3 4 5 6 7
1 2 3 4 5 6
1 1 2 3 4 5 6
2 2 4 6 8 10 12
3 3 6 9 12 15 18
4 4 8 12 16 20 24
5 5 10 15 20 25 30
6 6 12 18 24 30 36
i wrote like this and get this result
#include <iostream>
#include <iomanip>
using namespace std;
void main ()
{
int k,j,z;
int num=6;
for (z=1; z<=num; z++)
cout<<setw(4)<<z;
cout<<endl;
for (k=1; k<=num; k++)
{
for (j=1; j<=num; j++)
{
z=j*k;
cout<<setw(4)<<z;
}
cout<<endl;
}
cout<<endl;
}
result
1 2 3 4 5 6 7 8
1 2 3 4 5 6
1 2 3 4 5 6
2 4 6 8 10 12
3 6 9 12 15 18
4 8 12 16 20 24
5 10 15 20 25 30
6 12 18 24 30 36
but couldt work this out??
still new sorry. can anybody help with this????
Last edited on Mar 24, 2009 at 5:13pm UTC
Mar 24, 2009 at 7:58pm UTC
I fixed it by adding a space here and there.
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
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
int k, j, z;
int num = 6;
cout << " " ;
for (z = 1; z <= num; z++)
cout << setw(5) << z;
cout << endl << endl;
for (k = 1; k <= num; k++)
{
cout << k;
for (j = 1; j <= num; j++)
{
z = j * k;
cout << setw(5) << z;
}
cout << endl;
}
cout << endl;
return 0;
}
The result:
1 2 3 4 5 6 7 8
1 2 3 4 5 6
1 1 2 3 4 5 6
2 2 4 6 8 10 12
3 3 6 9 12 15 18
4 4 8 12 16 20 24
5 5 10 15 20 25 30
6 6 12 18 24 30 36
Hope that helps.
Mar 29, 2009 at 7:26am UTC
thanks eker676
i fixed that already like this
#include <iostream>
#include <iomanip>
using namespace std;
void main ()
{
int k,j,z;
int num=6;
cout<<" ";
for (z=1; z<=num; z++)
cout<<setw(5)<<z;
cout<<endl;
for (j=1; j<=num; j++)
{
cout<<setw(2)<<j;
for (k=1; k<=num; k++)
cout<<setw(5)<<j*k;
cout<<endl;
}
cout<<endl;
}
and get the result exactly how i wanted
1 2 3 4 5 6 7 8
1 2 3 4 5 6
1 1 2 3 4 5 6
2 2 4 6 8 10 12
3 3 6 9 12 15 18
4 4 8 12 16 20 24
5 5 10 15 20 25 30
6 6 12 18 24 30 36
Topic archived. No new replies allowed.