.编写程序是用来统计从键盘输入的一个正整数中各位数字中零的个数,并求各位数字中最大者。例如:1080其零的个数是2,各位数字中最大者是8。
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
//编写程序是用来统计从键盘输入的一个正整数中各位数字中零的个数,并求各位数字中最大者。例如:1080其零的个数是2,各位数字中最大者是8。
int main(){
int num,count=0,max=0;
scanf("%d",&num);
while(num){
int temp=num%10;
if(temp>max){
max=temp;
}
if(temp==0){
count++;
}
num=num/10;
}
printf("零的个数:%d,最大数:%d",count,max);
return 0;
}
#include <stdio.h>
int main()
{
int n,t,count=0,max=0;
printf("请输入正整数n: ");
scanf("%d",&n);
while(n)
{
t=n%10;
if(t==0)
count++;
else if(t>max)
max=t;
n=n/10;
}
printf("count=%d,max=%d\n",count,max);
return 0;
}
你题目的解答代码如下:
#include <stdio.h>
int main()
{
int n, count = 0, max = 0, t;
scanf("%d", &n);
do {
t = n % 10;
if (t == 0)
count++;
if (t > max)
max = t;
n /= 10;
} while (n > 0);
printf("零的个数:%d,最大数:%d", count, max);
return 0;
}
如有帮助,请点击我的回答下方的【采纳该答案】按钮帮忙采纳下,谢谢!