The bugs are for you to find! I'm wired in! Are you?
Friday, 4 May 2012
Calculating the sum of digits of a number in C
#include<stdio.h> #include<conio.h> int main() { 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(); return 0; }
No comments:
Post a Comment