C Program to Find Generic Root of a Number

C Program to Find Generic Root of a Number

C program to find the generic root of a number; Through this tutorial, we will learn how to find the generic root of a number using while loop and functions.

Programs to Find Generic Root of a Number in C

  • C Program to Find Generic Root of a Number
  • C Program to Find Generic Root of a Number using Function

C Program to Find Generic Root of a Number

/* C Program to Calculate Generic Root of a Number */
 
#include <stdio.h>
 
int main()
{
  int Number, Sum, Reminder;
 
  printf("\n Please Enter any number :- ");
  scanf("%d", &Number);
 
  while(Number >= 10)
  {
    for (Sum=0; Number > 0; Number= Number/10)
    {
      Reminder = Number % 10;
      Sum=Sum + Reminder;  
    }
    if(Sum >= 10)
    {
      Number = Sum;
    }
    else
    {
      printf("\n The Generic Root of a Given Number = %d", Sum);
      return 0;
    }
  } 
}

The output of the above c program; as follows:

Please Enter any number :- 50
Generic Root of a Given Number = 5

C Program to Find Generic Root of a Number using Function

/* C Program to Calculate Generic Root of a Number */
 
#include <stdio.h>
 
int Sum_Of_Digits (int); 
 
int main()
{
  int Number, Sum, Root;
 
  printf("\n Please Enter any number\n");
  scanf("%d", &Number);
  
  while(Number >= 10)
  {
    Sum = Sum_Of_Digits (Number);
    if(Sum >= 10)
    {
      Number = Sum;
    }
    else
    {
      printf("\n Generic Root of a Given Number = %d", Sum);
      return 0;
    }
  }	
}
 
int Sum_Of_Digits (int Number)
{
  int Reminder, Sum;
 
  for (Sum=0; Number > 0; Number = Number/10)
  {
     Reminder = Number % 10;
     Sum = Sum + Reminder;  
  }     
 return Sum;
}

The output of the above c program; as follows:

Please Enter any number :- 50
Generic Root of a Given Number = 5

Recommended C Programs

AuthorAdmin

My name is Devendra Dode. I am a full-stack developer, entrepreneur, and owner of Tutsmake.com. I like writing tutorials and tips that can help other developers. I share tutorials of PHP, Python, Javascript, JQuery, Laravel, Livewire, Codeigniter, Node JS, Express JS, Vue JS, Angular JS, React Js, MySQL, MongoDB, REST APIs, Windows, Xampp, Linux, Ubuntu, Amazon AWS, Composer, SEO, WordPress, SSL and Bootstrap from a starting stage. As well as demo example.

Leave a Reply

Your email address will not be published. Required fields are marked *