/* Calculate sum of digits using while loop */
#include<stdio.h>
int main()
{
int a, s;
printf("Enter value of a: ");
scanf("%d",&a);
s = 0;
while(a > 0)
{
s = s + (a%10);
a = a / 10;
}
printf("Sum of digits: %d",s);
return 0;
}
Related Post
Sum of digits using for loop
http://cbasicprogram.blogspot.in/2012/02/sum-of-digits-using-for-loop.html
#include<stdio.h>
int main()
{
int a, s;
printf("Enter value of a: ");
scanf("%d",&a);
s = 0;
while(a > 0)
{
s = s + (a%10);
a = a / 10;
}
printf("Sum of digits: %d",s);
return 0;
}
Related Post
Sum of digits using for loop
http://cbasicprogram.blogspot.in/2012/02/sum-of-digits-using-for-loop.html
great help ful
ReplyDeletein while loop condition should be a>1
ReplyDeleteThis comment has been removed by the author.
Deletevery much helpful
ReplyDeletevery helpful
ReplyDeletethanks
ReplyDelete