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

AuthorDevendra Dode

Greetings, I'm Devendra Dode, a full-stack developer, entrepreneur, and the proud owner of Tutsmake.com. My passion lies in crafting informative tutorials and offering valuable tips to assist fellow developers on their coding journey. Within my content, I cover a spectrum of technologies, including 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. Whether you're starting out or looking for advanced examples, I provide step-by-step guides and practical demonstrations to make your learning experience seamless. Let's explore the diverse realms of coding together.

Leave a Reply

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