C program for generic root

Posted By: Matpal Media - 1:42 AM
#include<stdio.h>
int main(){

long int num,sum,r;
printf("\nEnter a number:-");
scanf("%ld",&num);

while(num>10){
sum=0;
while(num){
r=num%10;
num=num/10;
sum+=r;
}
if(sum>10)
num=sum;
else
break;
}
printf("\nSum of the digits in single digit is: %ld",sum);
return 0;
}

0 comments:

Post a Comment

Note: Only a member of this blog may post a comment.