//竖式问题
#include<stdio.h>
#include<string.h>
int main(){
int i,ok,abc,de,x,y,z,count=0;
char s[20],buf[99];
scanf("%s",s);
for(abc=111;abc<=999;abc++)
for(de=11;de<=99;de++){
x=abc*(de%10);//计算abc*e的值并赋给x
y=abc*(de/10);//计算abc*d的值并赋给y
z=abc*de;
//printf输出到屏幕,fprintf输出到文件,sprintf输出到字符串
sprintf(buf,"%d%d%d%d%d",abc,de,x,y,z);
ok=1;
for(i=0;i<strlen(buf);i++)
if(strchr(s,buf[i])==NULL)
ok=0;
if(ok){
printf("<%d>\n",++count);
printf("%5d\nX%4d\n-----\n%5d\n%4d\n-----\n%5d\n\n",abc,de,x,y,z);
}
}
printf("The number of solutions =%d\n",count);
return 0;
}


strchr

原型:extern char *strchr(char *s,char c);

用法:#include <string.h>

功能:查找字符串s中首次出现字符c的位置

说明:返回首次出现c的位置的指针,如果s中不存在c则返回NULL。

举例:


// strchr.c

#include <syslib.h>
#include <string.h>

main()
{
char *s="Golden Global View";
char *p;

clrscr();

strchr(s,'V');
if(p)
printf("%s",p);
else
printf("Not Found!");

getchar();
return 0;
}

函数名: sprintf
功  能: 格式化输出到字符串中
用  法: int sprintf(char *string, char *farmat [,argument,...]);
程序例:

#include <stdio.h>
#include <math.h>

int main(void)
{
   char buffer[80];

   sprintf(buffer, "An approximation of Pi is %f\n", M_PI);
   puts(buffer);
   return 0;
}