This blog is under construction

Monday 10 June 2013

C program to print multiplication table from 1 to n

Write a C program to print multiplication table from 1 to n(up-to 16 numbers).



  /* multiplication table from 1 to n upto 16 numbers */
  #include <stdio.h>
  int main () {
        int i, j, n;
        printf("Enter the value for n:");
        scanf("%d", &n);

        for (i = 1; i <= n; i++) {
                printf("Multiplicaton table for %d\n", i);
                for (j = 1; j <= 16; j++) {
                        /* multiplication output */
                        printf("%2d X %2d = %3d\n", i, j, i * j);
                }
                printf("\n");
        }
        return 0;
  }



  Output:
  jp@jp-VirtualBox:~/$ ./a.out
  Enter the value for n:2
  Multiplicaton table for 1
   1 X  1 =   1
   1 X  2 =   2
   1 X  3 =   3
   1 X  4 =   4
   1 X  5 =   5
   1 X  6 =   6
   1 X  7 =   7
   1 X  8 =   8
   1 X  9 =   9
   1 X 10 =  10
   1 X 11 =  11
   1 X 12 =  12
   1 X 13 =  13
   1 X 14 =  14
   1 X 15 =  15
   1 X 16 =  16

  Multiplicaton table for 2
   2 X  1 =   2
   2 X  2 =   4
   2 X  3 =   6
   2 X  4 =   8
   2 X  5 =  10
   2 X  6 =  12
   2 X  7 =  14
   2 X  8 =  16
   2 X  9 =  18
   2 X 10 =  20
   2 X 11 =  22
   2 X 12 =  24
   2 X 13 =  26
   2 X 14 =  28
   2 X 15 =  30
   2 X 16 =  32





See Also:

1 comment: