WAP to find the sum of digits of the entered number.
#include<stdio.h>
#include<conio.h>
void main()
{
int num,i,rem,temp,s=0;
clrscr();
printf("\n Enter any number :");
scanf("%d",&num);
temp=num;
while(num>0)
{
rem=num%10;
s=s+rem;
num=num/10;
}
printf("\n Sum of Digits of %d is %d",temp,s);
getch();
}
Output:-
Enter any number
1234
Sum of Digits of 1234 is 10


0 Comments