//Program
#include<stdio.h>
void main()
{
int n,i,r;
int s=0;
clrscr();
printf("Enter any number:");
scanf("%d",&n);
while(n!=0)
{
r=n%10;
s=s+r;
n=n/10;
}
printf("Sum of digits=%d",s);
getch();
}
Sample Input/Output:
Enter any number:1234
Sum of digits=10
#include<stdio.h>
void main()
{
int n,i,r;
int s=0;
clrscr();
printf("Enter any number:");
scanf("%d",&n);
while(n!=0)
{
r=n%10;
s=s+r;
n=n/10;
}
printf("Sum of digits=%d",s);
getch();
}
Sample Input/Output:
Enter any number:1234
Sum of digits=10
No comments:
Post a Comment