这是横式:
111*11=1221
这是竖式:
111
* 11
------
1221
#include <stdio.h>
#include <stdlib.h>#include <math.h>
#include <time.h>
#include <string.h>
#define MAXN 20
#define MAXM 60
int main()
{
char s[MAXN],buf[MAXM];
int a,b,x,y,z,count=0,i,ok;
scanf("%s",s);
for(a=100; a<=999; a++)
for(b=10; b<=99; b++)
{
//对被乘数进行拆解然后再跟乘数求积
x=a*(b%10);
y=a*(b/10);
z=a*b;
sprintf(buf,"%d%d%d%d%d",a,b,x,y,z);
ok=1;
//判断乘数、被乘数、其中间过渡量以及结果是否只包含给出的数字
for(i=0; i<strlen(buf); i++)
if(strchr(s,buf[i])==NULL)
{
ok=0;
break;
}
if(ok==1)
{
printf("<%d>\n",++count);
printf("%5d\nX%4d\n-----\n%5d\n%4d\n-----\n%5d\n",a,b,x,y,z);
}
}
return 0;
}