#include<stdio.h>
int main(){
long int sum,num,m;
printf("Enter any number: \n");
scanf("%ld",&num);
while( num > 10 )
{
sum = 0;
while(num)
{
m = num%10;
num = num/10;
sum += m;
}
if(sum > 10)
num = sum;
else
break;
}
printf("Generic Root is: %ld\n",sum);
return 0;
}
2. Generic Root In One Line
#include <stdio.h>
int main(){
int num,m;
printf("Enter any number: ");
scanf("%d",&num);
printf("Generic root: %d",(m = num%9) ? m:9);
return 0;
}
Output:-
int main(){
long int sum,num,m;
printf("Enter any number: \n");
scanf("%ld",&num);
while( num > 10 )
{
sum = 0;
while(num)
{
m = num%10;
num = num/10;
sum += m;
}
if(sum > 10)
num = sum;
else
break;
}
printf("Generic Root is: %ld\n",sum);
return 0;
}
2. Generic Root In One Line
#include <stdio.h>
int main(){
int num,m;
printf("Enter any number: ");
scanf("%d",&num);
printf("Generic root: %d",(m = num%9) ? m:9);
return 0;
}
Output:-
0 Comments: