In C Programming Language:
Given an integer N, find whether the sum of the digits calculated repeatedly till a single digit is obtained results in the sum of 1 or not. Display 1 if the sum of the digits of N can equal 1 else display 0.
Example: For 199, Sum of digits = 1+9+9=19, 1+9=10, 1+0=1 so it should display 1
For 57, sum of digits = 5+7=12, 1+2=3 so it should display 0
#include<stdio.h> int getResult(int N){ int sum = 0; while(N>0){ sum += (N%10); N = N / 10; } if(sum<10){ return sum; } else{ return getResult(sum); } } int main () { int N, res; printf("Enter value for N: "); scanf("%d",&N); res = getResult(N); if(res == 1){ printf("1\n"); } else{ printf("0\n"); } return 0; }
Get Answers For Free
Most questions answered within 1 hours.