Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

PART I: PROGRAMMING EXERCISES Exercise #1: Write a C program that contains the following steps (make sure all variables are int). Read carefully each step

image text in transcribed
PART I: PROGRAMMING EXERCISES Exercise #1: Write a C program that contains the following steps (make sure all variables are int). Read carefully each step as they are not only programming steps but also learning topics that explain how functions in C really work. a. Ask the user for a number between 10 and 99. Write an input validation loop to make sure it is within the prescribed range and ask again if not. b. Commenting out the existing coding, write the code to divide a two digit integer number by 10 (pick any number you want between 10 and 99; hard code it right into the program rather than input it). Output the result as an integer. Try this with a few different initial numbers. For example, 59 would give an output of 5. c. Next write the code to find the remainder when a two digit number (again, hard code it into your program) is divided by 10 [note that this is done in a single statement). Output the result as an integer. Try this with a few different numbers. For example, 59 would give an output of 9. d. Comment the code from steps 4 and 5 out of your program, and put the coding to find the number of 10's in a number into a user defined (helper) function named f1. Set the initial number in a variable named x in the main function and print it out to check that it was set correctly). Your code will then pass x to a variable named y in f1 - the syntax for the call is of course f1(x); . (That is, you are copying the value in the argument variable x into the parameter variable y.) F1 should return the number of 10's in y. After fi returns, the main function should print the returned value. You should see the original number printed from the main function and the returned number of 10's in that original number, also printed from the main function. Try this with a couple of different initial numbers. e. Repeat step 6 but this time put the coding of the step 5 into another user defined (helper) function named f2. Again use y as the name of the parameter in f2; it will not get confused with the y in f1 - they are declared in separate functions and are thus completely different variables. (fi has its own y and f2 has its own y.) 12 should return the remainder when the passed (copied) number in y is divided by 10. After the setting of the initial number and printing it to check it, the main function should invoke (call) f2, and after f2 returns the main function should print the returned value. You should see the original number printed from the main function and the returned remainder when that original number is divided by 10, also printed from the main function. Try this with a couple of different initial numbers. f. Comment out the calls for fi and f2. Keep the assignment of a value to x and the print to check that it was properly set. Write a vold (no return value will be given) function f3 which will be passed the address of your initial number (x). The syntax for the call to this function is, of course f3(&x); The function f3 will have a single parameter, named x address, and that parameter must be able to hold the ADDRESS of an integer value, that address being copied from the ex. Check with you notes Ch 3 slide 7 to see how this should hoc

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases On The Web Designing And Programming For Network Access

Authors: Patricia Ju

1st Edition

1558515100, 978-1558515109

More Books

Students also viewed these Databases questions

Question

Did this statute unduly burden interstate commerce?

Answered: 1 week ago