Q) Write a program that accepts integer as input and repeatedly sums it digits till it reaches single digit. It the outputs that single digit.
I would like to know whether this is optimum or some better program can be written.(I haven't been taught functions yet).Code:#include<stdio.h>
int main()
{
int num,r,sum=0;
printf("Enter a no.");
scanf("%d",&num);
do{
while(num!=0){
r=num%10;
num/=10;
sum +=r;
}
if(sum >9){
num=sum;
sum=0;
}
}while(num!=0);
printf("the sum of digits is %d",sum);
}
Thanks for constructive remarks.