FIND OUT GENERIC ROOT OF A NUMBER By C PROGRAM


C program for generic root

#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;
}


C code for calculation of generic root in one line

#include <stdio.h>
int main(){         
int num,x;
printf("Enter any number: ");
scanf("%d",&num);
printf("Generic root: %d",(x=num%9)?x:9);
return 0;
}

Sample output:
Enter any number: 731
Generic root: 2

Meaning of generic root:
It sum of digits of a number unit we don't get a single digit. For example:
Generic root of 456: 4 + 5 + 6 = 15 since 15 is two digit numbers so 1 + 5 = 6
So, generic root of 456 = 6

8 comments:

Unknown said...

wap to find out car number with the help of following clues
1.it is 4digit number.
2.it is perfect square.
3.first two digits are same.
4.last two digits are same

Anonymous said...

7744
║#include
║#include
║#include
║void main()
║{
int a,b,c;
clrscr();
for(b=1;b<10;b++)
{
for(c=1;c<10;c++)
{
a=b+b*10+c*100+c*1000;
if(a==(int)sqrt(a)*(int)sqrt(a))
printf("%d ",a,sqrt(a));
}
}
}

Anonymous said...

there is an easier way to solve this...

Anonymous said...

This program prints the sum if it is 10
but 10 should be as 1+0=1 for the single digit sum


int sumofdigits(int num)
{
int sum=0;
int r;
while(num>9)
{
sum=0;
while(num)
{
r=num%10;
num/=10;
sum+=r;
}
if(sum>9)
num=sum;
}
return sum;
}
void main()
{
int num;
printf("Enter the number:");
scanf("%d",&num);
printf("%d",sumofdigits(num));
}

Anand said...

One logic may be like this:
(num-1)%9 +1;

Unknown said...

#include
int main()
{
int r,num=90,sum=0;
if(num>=10)
{
while(num!=0)
{
r=num%10;
num=num/10;
sum+=r;
}
printf("sum=%d",sum);
}
else
printf("sum=%d",num);
return 0;
}

Unknown said...

Cant u give me logic for counting float integer data type

Rakib said...

if i want to take 10^10000 as input ,how can i write the code ??? please help me .