C Program to Calculate Generic Root of a Number using Mathematical Formula

Lets write a C program to calculate Generic Root of a Number using Mathematical Formula.

Related Read:
C Program to Find Generic Root of a Number
C Program to Calculate Generic Root of a Number using Ternary Operator

For Example: If user input number is 589, then we add all the individual digits of the number i.e., 5 + 8 + 9 = 22. We get 22. Now we add individual digits of number 22 i.e., 2 + 2 = 4. So Generic Root of number 589 is 4.

Generic Root: We keep adding individual digits of a number until we get single digit output.

Formula To Calculate Generic Root

generic_root = 1 + ( (number-1)%9 );

Source Code: C Program to Calculate Generic Root of a Number using Mathematical Formula

 
#include < stdio.h >

int main()
{
    int num, res;

    printf("Enter a number above 10\n");
    scanf("%d", &num);

    printf("Generic Root of %d is %d\n", num, 1+((num-1)%9) );

    return 0;
}

Output 1:
Enter a number above 10
586
Generic Root of 586 is 1

Output 2:
Enter a number above 10
8
Generic Root of 8 is 8

Output 3:
Enter a number
589
Generic Root of 589 is 4

C Program to Calculate Generic Root of a Number using Mathematical Formula



YouTube Link: https://www.youtube.com/watch?v=pI0tOD_CrSs [Watch the Video In Full Screen.]


For list of all c programming interviews / viva question and answers visit: C Programming Interview / Viva Q&A List

For full C programming language free video tutorial list visit:C Programming: Beginner To Advance To Expert