Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • program to find out generic root of any number on C language

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 510
    Comment on it

    generic root means: in this we do addition of a given number until reached a single digit after addition . For example: Generic root of 784: 7 + 8 + 4 = 19 since 19 is a two digit numbers so 1 + 9 = 10.then again add 1 +0=1 So, generic root of 784 = 1

     #include<stdio.h>
        int main(){
        long int num, sum, r;
        printf("\n Enter a number:-");
        scanf("%d",&amp;num);
        while(num&gt;10){
        sum=0;
        while(num)
                       {
                             r=num%10;                           //we are taking modulus of the number
                             num=num/10;                         //now dividing number by 10
                             sum=sum+r;                              //take variable sum and store the value of r
                        }
        if(sum&gt;10)
                  num=sum;
        else
        break;
        }
        printf("\n Sum of the digits in single digit is: %d",sum);
        return 0;
        }
    
    Sample output:
    Enter any number: 245
    Generic root: 2
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: