shaswat
Advanced Member level 4
- Joined
- Jul 2, 2013
- Messages
- 115
- Helped
- 1
- Reputation
- 2
- Reaction score
- 1
- Trophy points
- 18
- Activity points
- 963
As a begineer I write a program of adding the places of a digit.
but if I enter a character e.g. "w" then it gives value -26. I don't understand how this works? I also debug my code and find that it takes value -29359(0x8D51)
Instead of this if I put a=0 then at output if I enter "a" then it shows 0. How it works as I want to understand.
Anyone can help??
Code:
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int a,b,sum=0,e,z;
printf("Enter the digit");
scanf("%d",&a);
while(a!=0)
{
b=a%10;
sum=sum+b;
a=a/10;
}
printf("the sum is %d",sum);
getch();
}
but if I enter a character e.g. "w" then it gives value -26. I don't understand how this works? I also debug my code and find that it takes value -29359(0x8D51)
Instead of this if I put a=0 then at output if I enter "a" then it shows 0. How it works as I want to understand.
Anyone can help??