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.
generic_root = 1 + ( (number-1)%9 );
#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
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