I made a program to sum all the integers out of any given number, but when i use zero as the number i get a huge negative number that increases as i keep running the program...for example given 123 for scanf function the program should return 6.
When i input 0 for the scanf function i get -402438064 then i run the program again with 0 and get -294000560. any explanation as to why its working this way?
#include <stdio.h>
int main(void) {
int num, lnum, last_result;
printf("ENTER A NUMBER:\n");
scanf("%i", &num);
do {
lnum = num % 10;
num /= 10;
last_result += lnum;
}
while (num != 0);
printf("%i\n", last_result);
return 0;
}