标签:printf sscanf break mic def res src ima http
问题描述:
代码:
1 //乘积的末三位 2 #include<stdio.h> 3 #include<ctype.h> 4 #define MAXN 1000 5 char s[MAXN]; 6 int main() 7 { 8 fgets(s,sizeof(s),stdin); 9 int i=0,result=1,n,sign=1; 10 while(s[i]) 11 { 12 if(isdigit(s[i])) 13 { 14 sscanf(s+i,"%d",&n); 15 if(sign==1) 16 { 17 printf("%d",n); 18 sign=0; 19 } 20 else printf("*%d",n); 21 result*=n; 22 23 for(i;s[i];i++) //i增加至当前连续数字字符结束 24 { 25 if(isalpha(s[i])) break; 26 } 27 } 28 i++; 29 } 30 31 printf("%%1000=%03d\n",result%1000); //格式化输出要打%,必须先打一个% 32 return 0; 33 }
运行结果:
标签:printf sscanf break mic def res src ima http
原文地址:https://www.cnblogs.com/bboykaku/p/12637197.html