首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

一百分求一小程序的代码解决思路

2012-02-12 
一百分求一小程序的代码设计一个C程序,输出如下九九乘法表:12345678911234567892246810121416183369121518

一百分求一小程序的代码
设计一个C程序,输出如下九九乘法表:
        1         2         3         4         5         6         7         8         9
1       1         2         3         4         5         6         7         8         9
2       2         4         6         8       10       12       14       16       18  
3       3         6         9       12       15       18       21       24       27
4       4         8       12       16       20       24       28       32       36
5       5       10       15       20       25       30       35       40       45
6       6       12       18       24       30       36       42       48       54
7       7       14       21       28       35       42       49       56       63
8       8       16       24       32       40       48       56       64       72
9       9       18       27       36       45       54       63       72       81


小弟很着急,麻烦尽快,谢谢!

[解决办法]
#include <stdio.h>
int main()
{ int i,j;
for(i=1;i <9;i++)printf( "%5d ",i);
for(i=1;i <=9;i++){
printf( "%d ",i);
for(j=1;j <9;j++)printf( "%4d ",i*j);
printf(\n);
}
}
[解决办法]
#include <stdio.h>
int main()
{ int i,j;
for(i=1;i <=9;i++)printf( "%5d ",i);
for(i=1;i <=9;i++){
printf( "%d ",i);
for(j=1;j <=9;j++)printf( "%4d ",i*j);
printf(\n);
}
}

[解决办法]
#include <stdio.h>

main()
{
int i,j;

for(i=1;i <=9;i++)
printf( "%4d ",i);
printf( "\n ");

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


[解决办法]


#include <stdio.h>
main()
{
int i,j,k=0;
char buffer[1000];
for(i=0;i <10;i++)
{
if(i==0)
{
k=sprintf(buffer, "\t ");
for(j=1;j <10;j++)k+=sprintf(buffer+k, "%d\t ",j);
}
else
{
for(j=0;j <10;j++)
if(j==0)k+=sprintf(buffer+k, "%d\t ",i);
else k+=sprintf(buffer+k, "%d\t ",i*j);
}
sprintf(buffer+k, "\n ");
}
printf( "%s ",buffer);
}
[解决办法]
#include <cstdlib>
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
int i,j;
for(i=1;i <=9;i++)
{
printf( "%3d ",i);
}
printf( "\n ");
for(i=1;i <=9;i++){
printf( "%d ",i);
for(j=1;j <=9;j++)
{
printf( "%2d ",i*j);
}
printf( "\n ");
}
system( "PAUSE ");
return EXIT_SUCCESS;
}

DEV-C++ 编译过了
正常运行没有问题

热点排行