## Featured Replies in this Discussion

- Sorry Thinker but you program doesn't hack it. Its full of syntax errors and undeclared variables, and it just plain doesn't work right. Line 10 does NOT calculate the sum of the digits. If the input number is 15 then the sum of the digits is 1 + 5 = 6. You are on the right track with line 9 but you flunked the course with line 10
- by Salem
- by Nick Evan
- by Nick Evan

Sorry Thinker but you program doesn't hack it. Its full of syntax errors and undeclared variables, and it just plain doesn't work right. Line 10 does NOT calculate the sum of the digits. If the input number is 15 then the sum of the digits is 1 + 5 = 6. You are on the right track with line 9 but you flunked the course with line 10

sorry buddy just try this out...

#include<stdio.h>

#include<conio.h>

void main()

{

int a,n,sum=0;

clrscr();

printf("Enter the number");

scanf("%d",&a);

do

{

n=a%10;

sum=sum+n;

a=a/10;

}

while(a=0);

printf("The sum of digits of the number %d is %d",a,sum);

getch();

}i think this should work....

...

}while(a=0) makes the while loop execute only once.

you mean while (a != 0)

you should verify your programs before submitting

u cn jst tr ds out dat cn wrk 4 any num f long integer range sch as 123456789 etc.,

Would you like to try that again in English?

Tada: the rulebook

- do not use kiddie-leet-speak

- use code tags when posting code

- do not resurrect year-old threads

- code formatting

- don't use scanf

- void main/int main/main

- getch() isn't standard C, getchar() is.

- clrscr();

- use meaningful names for your variables.

Should I continue? :)

```
/*sum of digits*/
#include<conio.h>
#include<stdio.h>
#include<math.h>
void main()
{
int num,n,digits,r,remainder,i,sum,m;
clrscr();
n=10;
m=1;
r=0;
sum=0;/*remember to initialize variables*/
printf("Enter The No\n");
scanf("%d",&num);
printf("Enter The No of digits\n");
scanf("%d",&digits);
for(i=1;i<=digits;i++)
{
num=num-r;
r=num%n;
remainder=(r/m);
sum=sum+remainder;/*modulus operator can not be used on float*/
n=n*10;
m=m*10;
printf("%d\n",remainder);
}
printf("%d\n",sum);
getch();
}
```