Sale!

COMP133 Assign # 2

$30.00 $18.00

Category: You will Instantly receive a download link for .zip solution file upon Payment || To Order Original Work Click Custom Order?

Description

5/5 - (4 votes)

Write a C program that asks the user to enter any four digit number. Your program should check whether the number is four digits or not and in case it is not a four digit number, the program should print a message and exit, otherwise it should do the following:

Print a menu as follows:

Select what you want to do with the number 1-3:
1- Print sum of even digits
2- Print sum of odd digits
3- Print relation of even/odd sum of digits larger/smaller/equal

The user should enter a value 1 to 3 which should be processed using a switch statement.

Your program should include at least two functions:
1- Function find_even_sum which takes a four digit number and returns the sum of its even digits.
2- Function find_odd_sum which takes a four digit number and returns the sum of its odd digits.

VERY IMPORTANT:

1. Turn in your assignment by replying to the course coordinator’s message on Ritaj and attaching your code file (main.c).

2. DO NOT SEND a MESSAGE To YOUR INSTRUCTOR WITH YOUR ASSIGNMENT. DOING so will RESULT in RECEIVING a GRADE of ZERO for the assignment even if YOU TURN it in by the due date and time.

3. You must include your full name, student id number, and lab section number in a comment at the beginning of your main.c code file.

Example of a Sample Runs:

Sample run 1:
Enter any four digit number
134829
134829 is not a four digit number, goodbye

Sample run 2:
Enter any four digit number
1235

Select what you want to do with the number 1-3:
1- Print sum of even digits
2- Print sum of odd digits
3- Print relation of even/odd sum of digits larger/smaller/equal
2
Sum of odd digits of 1235 is 9

Sample run 3:
Enter any four digit number
1831

Select what you want to do with the number 1-3:
1- Print sum of even digits
2- Print sum of odd digits
3- Print relation of even/odd sum of digits larger/smaller/equal
3
Sum of even digits in 1831 = 8 is larger than sum of odd digits = 5

Sample run 4:
Enter any four digit number
2132

Select what you want to do with the number 1-3:
1- Print sum of even digits
2- Print sum of odd digits
3- Print relation of even/odd sum of digits larger/smaller/equal
3
Sum of even digits in 2132 is equal to sum of odd digits = 4