Practice Assignment

(sumdigits.c)

Information

  1. Write a program that prints out the sum and product of the digits in an integer. Here are a few sample runs:
    Enter an integer (1 to 2,147,483,647 without commas): 1776
    The sum of the digits in 1776 is 21.
    The product of the digits in 1776 is 294.
    
    Enter an integer (1 to 2,147,483,647 without commas): 8
    The sum of the digits in 8 is 8.
    The product of the digits in 8 is 8.
    
    Enter an integer (1 to 2,147,483,647 without commas): 12345
    The sum of the digits in 12345 is 15.
    The product of the digits in 12345 is 120.
    
    Enter an integer (1 to 2,147,483,647 without commas): 2048
    The sum of the digits in 2048 is 14.
    The product of the digits in 2048 is 0.
    
    The numbers in RED are typed by the user.

    The name of the file should be sumdigits.c and the command to compile it will look like this:

    gcc -Werror -Wall -Wextra -ansi -pedantic sumdigits.c -o sumdigits -O2 -Wno-unused-result
    
    output-sumdigits.txt This output was generated by running the program 10 times, using each of these numbers:
    1
    42
    555
    1729
    65535
    142857
    8675309
    63288349
    999999937
    2147483647
    

Notes

For students that want to practice their C-fu