Program to find the sum of digits in a number in c language.
#include<stdio.h>
#include<conio.h>
void main()
{
int num ,rem,sum=0;
clrscr();
printf("enter a number =");
scanf("%d",&num);
while(num>0)
{
rem=num%10;
sum=sum+rem;
num=num/10;
}
printf("the sum of digits of number is =%d",sum);
getch();
}
■》Output->
enter a number =235
the sum of digits of number is =10
Comments
Post a Comment