In this tutorial you will learn about the C program to calculate Generic Root of a Number and its application with practical example.
C program to calculate Generic Root of a Number
In this tutorial, we will learn to create a C program that will calculate the Generic Root of a Number in C programming.
Prerequisites
Before starting with this tutorial, we assume that you are the best aware of the following C programming topics:
- Operators in C Programming.
- Basic Input and Output function in C Programming.
- Basic C Programming.
- Arithmetic Operators in C Programming.
- While Loop in the C programming.
What is the Generic Root of a Number?
In the generic root, it’s the terms of the mathematics where the units of the number are added to find a single-digit number.
Algorithm:-
1 2 3 4 5 6 7 8 9 10 11 |
1. Declaring the variable for taking the input from the user. 2. Taking the input of number from the user. 3. Passing that number to program code while loop. 4. Find the generic root of the number. 5. Printing the generic root. 6. End The Program. |
Program Description.
In today’s program, we will first take the input from the user in numbers more than a single digit. And then we will pass that variable to a while loop for the finding of the generic root of the number. At last, we will print the result generic root of the user after the
With the help of the below program, we can calculate the Generic Root of a Number.
Program Code:-
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
/* C Program to Calculate Generic Root of a number */ #include <stdio.h> int main() { //Declaring the required variable for the program. int no, Sum, rmdr; //no = input number from the user for the program. //Sum = it will hold the sum value of digits. //rmdr = it will hold the remainder of the number. //Taking the input no from the user. printf("\n Please Enter any number\n"); //Scanning the required variable for the program. scanf("%d", &no); //Finding the generic root of the number . while(no >= 10) { for (Sum=0; no > 0; no= no/10) { rmdr = no % 10; Sum=Sum + rmdr; } if(Sum >= 10) { no = Sum; } else { //Printing the output for the program. printf("\n The Generic Root of a Given number = %d", Sum); return 0; } } } |
Output:-
In the above program, we have first initialized the required variable.
- no = it will store the input integer value.
Taking the input from the user in number.
Calculating the generic root of the number.
Printing the output of the program.