C Program to Sum of Digits of a Number repeatedly until a single-digit occurs

Write a program to find the sum of digits of a number repeatedly until a single digit occurs

Example:
1647 => 1 + 6 + 4 + 7 = 18 => 1+ 8 = 9

Input Format
Input contains an integer N

Output Format
Print the final sum

Constraint
1<=N<=1000000

Sample Input 1

392

Sample Output 1

5

Code:

#include<stdio.h>

int main()
{
int i,n,sum=0,rem;
scanf("%d",&n);


while(n>0 || sum>9){
    if(n==0){
return 0;
}
Code language: C/AL (cal)

Leave a Comment