Hey all...also, i've started assembly on Intel 64 after dipping into C on FreeBSD for the past year. Would like to start using GDB.
Code:
// Program to give sum of digits of a number
#include <stdio.h>
int main(void)
{
long num, temp, digit, sum = 0;
printf("Enter your number.\n");
scanf("%ld", &num);
temp = num;
// num = 103
while ( num > 0)
{
digit = num % 10;
sum = sum + digit;
num /= 10;
}
printf("Given number = %ld\n", temp);
// output 103, 4
printf("Sum of the digits %ld = %ld\n", temp, sum);
}
specifically, this while loop:
Code:
while ( num > 0)
{
digit = num % 10;
sum = sum + digit;
num /= 10;
{
Is this while loop looping num times until it reaches the value of greater than 0? Please expain.
103 % 10 = 3 (digit)
0 (sum) = 0 (sum) + 3
103 (num) = 103 (num) / 10 (compound operator, division)
Sincerely, lost