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

    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. #2
    Señor Member
    Join Date
    Jan 2002
    Posts
    561
    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. #3
    ¡Amo fútbol!
    Join Date
    Dec 2001
    Posts
    2,136
    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. #4
    Registered User
    Join Date
    Nov 2001
    Posts
    162
    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. #5
    Unregistered
    Guest
    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. #6
    Unregistered
    Guest

    Unhappy

    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. #7
    Unregistered
    Guest

    Red face

    setw and setprecision


    oops

  8. #8
    Unregistered
    Guest

    Thumbs up 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;
    }


    thanks for the advice

  9. #9
    Registered User
    Join Date
    Dec 2001
    Posts
    11

    table

    check this attachment
    Attached Files Attached Files
    All is well that ends well

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. trying to make a KenGen ( for a game tool )
    By lonewolfy in forum C# Programming
    Replies: 4
    Last Post: 03-28-2007, 08:23 AM
  2. Win32 Common Controls in C++, how do i make and use them?
    By C+noob in forum Windows Programming
    Replies: 6
    Last Post: 01-09-2006, 10:53 AM
  3. how do i make a mathematical table using loops.
    By gad n' gaz in forum C Programming
    Replies: 13
    Last Post: 10-18-2005, 02:15 PM
  4. problem with db table
    By WaterNut in forum Windows Programming
    Replies: 5
    Last Post: 06-16-2004, 02:52 PM
  5. multiplication table
    By SpEkTrE in forum C Programming
    Replies: 2
    Last Post: 12-09-2003, 03:46 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21