Q:

C Program For Find A Generic Root Of Number Using While Loop

belongs to collection: Loops C Programs for Practice

0

 

Generic Root: of a number is sum of all the digits of the number until we get a single-digit output.

If user input number is 12345, then we add all the individual digits of the number i.e., 1 + 2 + 3 + 4 + 5 = 15. We got 15. Now we add individual digits of number 15 i.e., 1 + 5 = 6. So Generic Root of number 12345 is 6.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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

}

 

Output:

Enter any number :

456791

Generic Root is :5

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

C Program To Print A Calendar By Taking Input From... >>
<< C Program to Count Number of Digits of a Number (I...