Sum of digit

#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int n,num,x,sum=0;
printf("Enter a number=");
scanf("%d",&n);
while(n>0)
{
x=n%10;
sum=sum+x;
n=n/10;
}
printf("Sum of digits of a number=%d",sum);
getch();
}

Output:
Enter a number=123
Sum of digits of a number=6

ليست هناك تعليقات:

إرسال تعليق