# How to make a multiplication table up to 10*10=100?

• 01-09-2002
Unregistered
How to make a multiplication table up to 10*10=100?
my syntax looks like this:

*/

// Includes

#include<iostream.h> // for << and >>
#include<iomanip.h> // for setw and setf

int main ()
{
cout.setf(ios::fixed, ios::floatfield); // Set up floating point
cout.setf(ios::showpoint); // output format

// Declaration and initialization of variables
int n1 = 1;
int n2 = 2;
// Main Function statements
for(n1=1; n1<=6; n1++)
{
cout << setw(5) << n1;
for(n2=(n2*n1); n2<=(n1*10); n2++)
{
cout << setw(5) << n2;
}
cout << endl;
}
return 0;

}// end main

and this is the output i get:

1 2 3 4 5 6 7 8 9 10
2
3
4
5
6

how do i fix this so the table fills in....and in the first "for" loop if i put

n1<=7

(or any digit more than 6)
it will look like a million numbers coming up
• 01-09-2002
tim545666
I had to do this earlier in the year, and I think the way i did it was by rows, except for the top. I used a seperate loop for that. But this is not the kind of problem someone should be writing for you. It is pretty importand for you to be able to figure this out on your own, it really helps you understand nested loops.
• 01-09-2002
golfinguy4
You are making things much more harder than they need to be. Have a nested loop where one goes through the rows while the other goes through the columns. THen, have the screen display the product of the rows and columns.
• 01-09-2002
Crossbow
What do those setw and setf functions do? when I first started C++ nested loops were difficult for the to understand, but now I do understand them. If you have this:

for(i=0; i<10; i++){
for(j=0; j<10; j++){
...........blah blah blah
}
}

it would loop through the first loop once and in the one time it goes though the second loop 10 times. Then it gets to the second time around the first loop and does the second loop 10 more times. So in the end you would have 100 total loops. I hope this helps you.
• 01-09-2002
Unregistered
Hi,

This was the stuff,which is pretty similar to urs...

Code:

#include<iostream.h>
int main()
{
int counter;
counter=1;

cout<<"N"<<" "<<"2*N"<<" "<<"3*N"<<endl;
while(counter<10)
{
cout<<counter<<" "<<2*counter<<" "<<3*counter<<endl;
counter++;

}
return 0;
}

I hope this helps.
• 01-10-2002
Unregistered
its supposed to be setw and setp

setw is used to determine how many columns a output variable will have and setp is for its decimal places

the program has to contain two "for" loops....one inside the other(nested)

i still can't get it
• 01-10-2002
Unregistered
setw and setprecision

oops
• 01-11-2002
Unregistered
yeehaw got it done
my syntax:

*/

// Includes

#include<iostream.h> // for << and >>
#include<iomanip.h> // for setw and setf
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//~~~~~~~~~~~~~~~~~~~~~~ Main Program ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~

int main ()
{
cout.setf(ios::fixed, ios::floatfield); // Set up floating point
cout.setf(ios::showpoint); // output format

// Declaration and initialization of variables
int r = 1; // row numbers

// Main Function statements
for(r=1; r<=10; r++)
{
cout << setw(5) << r;
int c = 2; // column numbers
for(c=(c*r); c<=(r*10); c=c+r)
{
cout << setw(5) << c;
}
cout << endl << endl << endl << endl << endl << endl;
}
return 0;
}