C语言:从键盘输入正整数n,在屏幕上输出>= n 的最小哈沙德数,咋编?

2024-11-08 03:38:08
推荐回答(1个)
回答(1):

代码文本:

#include "stdio.h"

int main(int argc,char *argv[]){

int n,t,k;

printf("Enter n(int n>0)...\nn=");

if(scanf("%d",&n)==1 && n>0)

while(n){

for(t=n,k=0;t;k+=t%10,t/=10);

if(n%k==0){

printf("The result is %d.\n",n);

break;

}

n++;

}

else

printf("Input error, exit...\n");

return 0;

}