donmike25 icon

inlab(3)2013

donmike25 | PRO | 07/09/13 09:46:56 AM UTC | 0 ⭐ | 208 👁️ | Never ⏰ | []
C |

1.06 KB

|

None

|

0 👍

/

0 👎

#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