案例分析题 编写程序,任意输入一个正整数,求出该正整数中最大的数字和最小的数字,如果该整数是个位数的话,最大的数字和最小的数字就是它本身。
【正确答案】#include void main () { int a=0; int max=0, min=0; int temp; while(a<=0) { scanf("%d", &a); } if(a>0 && a<10) { printf("max=%d,min=%d/n",a,a); return; } max=a%10; min=a%10; while(a>0) { temp=a%10; if(maxtemp) { min=temp; } a=a/10; } printf("max=%d,min=%d/n",max,min); } 评分标准: 循环输入一个正整数2分; 判断是否是个位数3分; 求最大数字和最小数字8分; 其余2分;
【答案解析】