Wednesday, 19 August 2015

Programming in C to find the sum of the given number

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

No comments:

Post a Comment