If a five digit number is input through the keyboard, write a program to calculate the sum of its digits.


 #include<stdio.h>

void main()

{

int num,sum=0,ld;

printf("Enter a five digit number =");

scanf("%d",&num);

ld=num%10;

num=num/10;

sum=sum+ld;

ld=num%10;

num=num/10;

sum=sum+ld;

    ld=num%10;

num=num/10;

sum=sum+ld;

ld=num%10;

num=num/10;

sum=sum+ld;

ld=num%10;

num=num/10;

sum=sum+ld;

printf("sum of the digits =%d",sum);

}


Post a Comment (0)
Previous Post Next Post