3/20/2016

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

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


Previous Post
Next Post

post written by:

Hi, I’m Ghanendra Yadav, SEO Expert, Professional Blogger, Programmer, and UI Developer. Get a Solution of More Than 500+ Programming Problems, and Practice All Programs in C, C++, and Java Languages. Get a Competitive Website Solution also Ie. Hackerrank Solutions and Geeksforgeeks Solutions. If You Are Interested to Learn a C Programming Language and You Don't Have Experience in Any Programming, You Should Start with a C Programming Language, Read: List of Format Specifiers in C.
Follow Me

0 Comments: