Question
This is a C programming question: Rules: 1. I will give you a bunch of coding problems and you code them in a single file
This is a C programming question:
Rules:
1. I will give you a bunch of coding problems and you code them in a single file (Lab07.c).
When you are finished, main will exercise (execute) all of the functions, sequentially. The main portion of your program is the driver; it does not implement the solutions.
You are not allowed to have flow control statements (no looping, no branching) in main. In main you are only allowed to call the functions you write with the exceptions of
scanf and printf.
2. Thoroughly document your code by commenting, both to document what each function does, and how each step of the function accomplishes its task. Indent each functional level as we have discussed in class, especially to show subordination.
3. You can create as many functions as you like in completing the tasks below. That is, a problem may be solved by employing multiple (new) functions.
Functions other than main are allowed to have flow control statements but they are not allowed to have any calls to scanf or printf unless otherwise specified.
4. Repetitive code will be penalized. That is, if you find that you are using the same group of statements, over and over, you should consider encapsulating that code in a function.
5. Make sure all of your code and its output are nicely formatted and easy to understand. That is, organize and label the output so that it is easy to tell what the function is performing and what the output represents.
Problem 0
Create an integer function that prompts the user for a positive integer. The function should return that integer. Call this function and print the result from main. This function may use scanf and printf.
Problem 1 Ask the user to enter some number n of positive integers. Determine the mean (average) of the numbers
entered. Print the result.
Problem 2
Ask the user to enter a positive integer. Calculate the floor of the input's square root. That is, calculate the greatest integer less than or equal to the inputs square root. Print the result. (Do not use any outside functions such as sqrt.)
Problem 3
Ask the user to enter two positive integers. Calculate the greatest common divisor of the two numbers. Print the result.
Problem 4
Create and initialize an array of 10 integers in main. Print them using a function of your creation. That is, make a function (that employs printf) to print the elements of the integer array that is passed in through its calling arguments.
Problem 5
A vector dot product is an algebraic operation on two equal-length vectors. The dot product of two vectors a = [a1, a2, a3,...an] and
b = [b1, b2, b3,...bn]
is: a1*b1 + a2*b2 + a2*b3 + ...+ an*bn Create and initialize two integer arrays (i.e., vectors) in main that contain 10 elements each. Display the vectors using your solution to Problem 4, then calculate and print their dot product.
Problem 6
Create a 10x10 integer array in main. You may create a function to initialize this array. Create a function to display this 2D array as a 10x10 block. Use your solution from problem 4 to display the elements. Do not use printf in this new function (or in main).
Problem 7
Create an integer function to sum all of the elements of a 10-by-10 array. Print the sum of the elements of the array used in the preceding problem.
Challenge:
A perfect number is a positive integer that is equal to the sum of its factors excluding itself. For example, 6 is a perfect number because 1+2+3 = 6. Ask the user to enter a positive integer, then display the next largest perfect number. For example, if the user enters 5, the output should be 6. If the user enters 6 the output should be 28.
HINT: Consider creating more than one function. Break the problem down into individual steps. When complete, submit your file via Canvas.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started