C Program: Multiplication Table

Here is a C program for printing a multiplication table based on a user input n. The resulting table will be n x n. The maximum input is limited to 15 in order for the results to readable. Higher input will scroll the results.

#include 
#include 

int number, row, column, result;

main(void)
{
    /*Input Area - Input number must be from 0 to 15, else input loop will continue */

    do
    {
          system("cls");
          printf("Enter max value: ");
          scanf("%d", &number);
          result=number;
    } while ((number<0)|(result>15));

    /* Output Area - row and column are used as counters and
        initialized to 0 as to requirements.
       Final values are compared to the input number
       Inner do-while prints per column in a line.
       Outer do-while moves the cursor to the next line
    */

    row=0;
    do
    {
        column=0;
        do
        {
              result=row*column;
              if (result<1)
                  printf("");
              else if (result<10)
                  printf("  %d  ", result);
              else if (result<100)
                  printf(" %d  ", result);
              else if (result<1000)
                  printf("%d  ", result);
              else
                  printf("");
              column++;
        } while (column<=number);

        printf("\n");
        row++;
    } while (row<=number);
    system("pause");

The above code will generate this output.

multiplication table output of a  C program

Share and Enjoy:
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • BlogMemes
  • Fark
  • StumbleUpon
  • NewsVine
  • Spurl
  • Technorati
  • TwitThis

Sorry, comments for this entry are closed at this time.