大家快来做题拉拉拉...................
汗,都懒得写代码了.......... cheat了一个威望,哈.....
不错不错
#include <stdio.h>
#include <conio.h>
void main()
{
long num,temp;
int total=0;
clrscr();
printf("INPUT number:\n ");
scanf("%ld",&num);
printf("\n\t%ld",num);
temp=num;
while((num/10)!=0){
total+=(int)(temp%10);
if((temp/10)==0)
{num=(long)total;printf("---%d",total);temp=num;total=0;}
else
{temp=temp/10;}
}/*while*/
getch();
}
求数根:例如39
是这样求到的39--->3+9=12--->1+2=3结束.
123456--->1+2+3+4+5+6=16=1+6=7结束. 1+2+3+4+5+6=21=2+1=3 加错了哦
#include <stdio.h>
long get( long );
main()
{
long n;
printf("please input a number : ");
scanf("%ld",&n);
while(n>9)
{
n=get(n);
}
printf("the result is %ld \n",n);
}
long get(long n)
{
long temp=0;
while(n)
{
temp+=n%10;
n/=10;
}
return temp;
}