C Multiplication Table

This is a discussion on C Multiplication Table within the C Programming forums, part of the General Programming Boards category; Im having trouble writing a multiplication table for C. I have actually wrote the programme, without any user interface, however ...

  1. #1
    Registered User
    Join Date
    Oct 2009
    Posts
    28

    C Multiplication Table

    Im having trouble writing a multiplication table for C.
    I have actually wrote the programme, without any user interface, however i want user interface, i want the user to be able to choose what multiplication they see.
    e.g. if the put in 5 & 6 in then they will see the following:

    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


    here is the code that i have so far :

    Code:
     {
    
       int number1;
       int number2;
       int result;
    
       for (number1 = 1 ; number1 <= 12 ; number1++)
          {
          for (number2 = 1 ; number2 <= 12 ; number2++)
             {
             result = number1 * number2;
             printf ("%4d ",result);
             }
          printf("\n");
          }
       }
    and the output i get with that is a standard 12x12 table without any user interface.

  2. #2
    Registered User
    Join Date
    Feb 2009
    Posts
    35
    firstly, you need to get the numbers from the user with something like

    Code:
    scanf("%d", &number);
    secondly, your for loop doesnt do quite what you expect it to do

    Code:
       for (number1 = 1 ; number1 <= 12 ; number1++)
    this makes number1 equal to one (overwriting any information that was stored in this variable) and goes all the way up to twelve. what you want is for it to start at one and go up to a certain number which the user inputs. so you will have to change this a little bit.

    you probably need a few extra variables.

  3. #3
    Registered User
    Join Date
    Oct 2009
    Posts
    28
    Ive managed to get it working

    below is what i have done:

    Code:
       int number1;
       int number2;
       int result;
       int first;
       int second;
    
       printf("Please enter a positive value for number 1 ");
    scanf("%d", &number1);
       printf("Please enter a positive value for number 2 ");
    scanf("%d", &number2);
    
       for (first = 1 ; first <= number1 ; first++)
          {
          for (second = 1 ; second <= number2 ; second++)
             {
             result = first * second;
             printf ("%4d ",result);
             }
          printf("\n");
          }
       }
    Thanks for your reply

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. help with structs and malloc!
    By coni in forum C Programming
    Replies: 20
    Last Post: 09-14-2009, 06:38 PM
  2. Multiplication table (need guide)
    By naspek in forum C Programming
    Replies: 21
    Last Post: 07-23-2009, 07:26 AM
  3. Multiplication table
    By freddyvorhees in forum C++ Programming
    Replies: 6
    Last Post: 08-02-2008, 12:09 PM
  4. Writing array, to file
    By zootreeves in forum C Programming
    Replies: 9
    Last Post: 09-08-2007, 06:06 PM
  5. multiplication table
    By SpEkTrE in forum C Programming
    Replies: 2
    Last Post: 12-09-2003, 04:46 PM

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