Multiplication table with rows and columns

China☆狼群 提交于 2019-12-11 01:48:29

问题


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

回答1:


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;

}




回答2:


You have to print your table line by line, not column by columne.

So you have to

printf("%d*%d=%d %d*%d=%d %d*%d=%d\n",...);

Rest figure out yourself, if you have problems, write and I'll help you further.




回答3:


This will work perfectly:

#include<stdio.h>

int main(){
int i, j=1;


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

return 0;
}


来源:https://stackoverflow.com/questions/19223788/multiplication-table-with-rows-and-columns

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!