Search code examples
cformattingprintfmultiplication

Multiplication table with rows and columns


How can I make multiplication table to look like this: http://i.imgur.com/rR6JSua.png ?

With my code it only has one column.

#include<stdio.h>

int main()
{
    int i, j;

    for(i = 1;i <= 9;i++)
    {   
        for(j = 1;j <= 9;j++)
        {
            printf("%d * %d  = %d\n",i , j,i*j);
        }
        printf("%d * %d = %d\n",i , 10,i*10);
        printf("\n");
    } 

    return 0;
}

Solution

  • Try This:

    #include<stdio.h>
    
    int main()
    {
        int i, j;
    
    for(i = 1;i <= 9;i+=3)
    {
    
      for(j = 1;j <= 10;j++)
      {
    
           printf("%2d * %2d = %2d ",i , j,(i)*j);
           printf("%2d * %2d = %2d ",i+1 , j,(i+1)*j);
           printf("%2d * %2d = %d\n",i+2, j,(i+2)*j);
      }
      printf("\n");
    } 
    return 0;
    

    }