Write a program to find sum of digits in a given number
#include<stdio.h>
#include<conio.h>
void main()
{
int n,sum=0,digit;
clrscr();
printf("enter the number: ");
scanf("%d",&n);
while(n!=0)
{
digit=n%10;
sum=sum+digit;
n=n/10;
}
printf("Sum of digits=%d",sum);
getch();
}
Output:
enter the number: 456
Sum of digits=15
No comments: