donmike25

inlab(3)2013

Jul 9th, 2013
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.06 KB | None | 0 0
  1. #include<stdio.h>
  2.  
  3.      
  4.      
  5.     int main(){
  6.      
  7.      
  8.             int num,sum=0,r;
  9.            
  10.             do{
  11.             printf("Enter a 5-digit positive number: ");
  12.             scanf("%d",&num);
  13.            
  14.            
  15.             if (num<0)
  16.             {
  17.                     printf ("Sorry,this is not a 5-digit positive number/n");
  18.             }
  19.            
  20.             else
  21.             {
  22.                     if (num>= 10000 && num < 100000)
  23.                     {
  24.                             for(;num!=0;num=num/10)
  25.                             {
  26.                             r=num%10;
  27.                             sum=sum+r;
  28.                             }
  29.      
  30.                     printf("Sum of digits of number:  %d\n",sum);
  31.                     break;
  32.                     }
  33.                    
  34.                     else
  35.                     {
  36.                             printf ("Sorry,this is not a 5-digit positive number/n");
  37.                     }
  38.            
  39.             }
  40.            
  41.             }while(1);
  42.       return 0;
  43.     }
Advertisement
Add Comment
Please, Sign In to add comment