Friday, July 23, 2010

C program that adds the digits of whole numbers

------------------------------------
#include
int main() {
int in,temp,sum=0;
printf("Enter a value: ");scanf("%d",&in);
while(in!=0){
temp=in%10;
sum+=temp;
in/=10;
}
printf("%d\n",sum);
getch();
}
------------------------------------
input <123>
the output would be<6>

No comments:

Post a Comment