Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- int main(){
- int num,sum=0,r;
- do{
- printf("Enter a number: ");
- scanf("%d",&num);
- if (num<0)
- {
- printf ("PLease Enter a positive 5 digit 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 ("PLease Enter a 5 digit number\n");
- }
- }
- }while(1);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement