Hi folks,
Just wanted to share a program I made. It was the answer to one of the end chapter exercises in the C programming book I'm using, asking the reader to create a program that adds all the digits of an integer. It's nothing special, and I'm not sure what practical use it could have, but I'm proud of it because in the past this type of thing would have frustrated me and I would have given up, but now the challenge of figuring things out excites me. Oh and I just thought "fuse" would be a fun word for the context :P
Code:
/* Program to calculate the sum of the digits in an integer */
#include <stdio.h>
int main ()
{
int number, right_digit, sum = 0;
printf ( "\nWhat number do you wanna fuse? ");
scanf ( "%i", &number );
printf ("\n");
while ( number != 0) {
right_digit = number % 10;
sum += right_digit;
number = number / 10;
}
printf ( "The sum of the digits is %i.", sum );
printf ("\n\n");
return 0;
}