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

This is a discussion on How to make a multiplication table up to 10*10=100? within the C++ Programming forums, part of the General Programming Boards category; my syntax looks like this: */ // Includes #include<iostream.h> // for << and >> #include<iomanip.h> // for setw and setf ...

1. ## 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

2. 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.

3. 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.

4. 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.

5. 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.

6. 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

7. setw and setprecision

oops

8. ## 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;
}