top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

c program to find out generic root of a number?

+3 votes
496 views
c program to find out generic root of a number?
posted Jun 4, 2015 by Mohammed Hussain

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+1 vote
 
Best answer
#include<stdio.h>
int main(){

  long int num,sum,r;
  printf("\nEnter a number:-");
  scanf("%ld",&num);

  while(num>10){
    sum=0;
    while(num){
      r=num%10;
      num=num/10;
      sum+=r;
    }
    if(sum>10)
      num=sum;
    else
      break;
  }
  printf("\nSum of the digits in single digit is: %ld",sum);
  return 0;
}

Sample output:

Enter any number: 731
Generic root: 2

Meaning of generic root:

It sum of digits of a number unit we don't get a single digit. For example:
Generic root of 456: 4 + 5 + 6 = 15 since 15 is two digit numbers so 1 + 5 = 6
So, generic root of 456 = 6

answer Jun 9, 2015 by Manikandan J
Similar Questions
+1 vote

Given an array of integers (possibly some of the elements negative), write a C program to find out the *maximum product* possible by adding 'n' consecutive integers in the array, n <= ARRAY_SIZE.

Also give where in the array this sequence of n integers starts.

+5 votes

Help me to write a C program which can generate list of numbers which are palindrome in decimal and octal notion. You can take some max as a limit find out all numbers which satisfy the given property between 1 to n.

...