#include <stdio.h>
#define MAXN 100
int main(){
int data[MAXN];
int number;
int a,b;
int j;
int i;
int copyb;
int copya;
int count;
int l=0;
scanf("%d",&number);
//printf("%d\n",copynumber);
while(number--){
scanf("%d%d",&a,&b);
if(a>=10000||b>=10000||a<0||b<0){
break;
}else{
printf("%8d\nx%7d\n--------\n",a,b);
if(b>=1&&b<=9){
printf("%8d\n********************\n",a*b);
}else{
copyb=b;
copya=a;
for(i=1;b/10!=0;i++){
//printf("1\n");
b/=10;
}
j=0;
b=copyb;
//printf("copyb=%d\n",copyb);
//printf("b=%d\n")
while(i>0){
//printf("xx\n");
data[j]=b%10;
//printf("%d \n",data[j]);
b/=10;
j++;
i--;
}
//printf("count=%d\n",count);
//for(j=0;j<=count-1;j++){
// printf("%d ",data[j]);
//}
i=j;
j=0;
//b=copyb;
//printf("b=%d\n",b);
int c;
int h=0;
int m;
int copydata;
while(j<=i-1){
copydata=data[j];
m=copydata*a;
for(c=1;(m)/10!=0;c++){//Èç¹ûm¸ÄΪcopydata*aÔò»áÓдíÎó
//printf("1");
m/=10;
}
//printf("c=%d\n",c);
//count=j+1+c;
count=8-h-c;
//printf("count=%d\n",count);
for(;count>0;count--){
printf(" ");
}
h++;
printf("%d\n",data[j]*a);
j++;
}
/*if(copya/10==0||copyb/10==0){
printf("%8d\n",copya*copyb);
}else{*/
printf("--------\n%8d\n",copya*copyb);
for(i=1;i<=20;i++){
printf("*");
}
printf("\n");
}
}
}
return 0;
}注意各位数的情况比如33*3,总结各种情况要考虑周全

本文分享了一个使用C语言编写的程序,该程序能够接收两个整数作为输入,并以特定格式输出这两个数相乘的过程及结果。适用于学习C语言基本语法、数组使用以及格式化输出。

446

被折叠的 条评论
为什么被折叠?



