Program Code:
#include<stdio.h>
#include<conio.h>
int main()
{
int num , sum = 0 , mod ;
printf("Enter any number = ");
scanf("%d",&num);
sum = 0;
while(num)
{
mod = num % 10 ;
sum = sum + mod ;
num = num / 10 ;
}
printf("\n\nSum of digits of given number is = %d",sum);
getch();
}
Output:
Enter any number = 55
Sum of digits of given number is = 10
No comments:
Post a Comment