问题
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