#include<stdio.h>
int main(){
int num,sum=0,r;
do{
printf("Enter a 5-digit positive number: ");
scanf("%d",&num);
if (num<0)
{
printf ("Sorry,this is not a 5-digit positive number/n");
}
else
{
if (num>= 10000 && num < 100000)
{
for(;num!=0;num=num/10)
{
r=num%10;
sum=sum+r;
}
printf("Sum of digits of number: %d\n",sum);
break;
}
else
{
printf ("Sorry,this is not a 5-digit positive number/n");
}
}
}while(1);
return 0;
}
Comments