Question
Write program in c with comments Use the GetIntegerfunction(void) to get a number from the user Get the number from the user(n)(For example if the
Write program in c with comments
Use the GetIntegerfunction(void) to get a number from the user
Get the number from the user(n)(For example if the user enters a 4, each loop below will repeat 4 times)
Calculate the sum of the squares of the first (n) number susing a for loop.
For example, if the user entered a 4, you would calculate 1*1 + 2*2 + 3*3 + 4*4 and print the total
onto the screen
Calculate the product of the squares of the first (n) numbers using awhile loop.For example, if the user entered a 4, you would calculate (1*1) * (2*2) *(3*3) *(4*4) and print the
total ontothe screen. Note: You will be graded on whether or not you used the correct loop as described above, not just on
output
PART 2:
Write a small program that calculates the perimeter and area of a square using pass by reference function arguments
//asks and gets an integer from the user
int GetInteger(void);
//takes one integer argument and two integer pointer arguments
//1. calculate the area of the square and store the result in areaPtr
//2.calculate the perimeter of the square and store the result in perimeter
Ptrvoid CalculateBothSquare(intside, int*areaPtr, int *perimeterPtr);
Call all thefunctions from main.
Note:No calculations may be done in the main function.
Code should be well commented!
Main function(hints):
1.Declare variables:number, sumTotal, productTotal,length, squareArea, squarePerimeter,
2.Dont forget to initialize sumTotal and productTotal
3.Call GetInteger to get a number from the user for the loops
4.Calculate and print the sumTotal
5.Calculate and print the productTotal
PART 2
6.Call GetInteger to get the length of the side of the square
7.Pass the length, address of squareArea, and address of squarePerimeter to the CalculateBothSquare function
8.Print the area and the perimeter onto the screen
NOTE: The area and perimeter should be printed twice, once from inside the functionsand then a second time in the main function
(See sample output below)
CalculateBoth
Square
function
logic (and hints):
Calculate the
area and store the result in the
value at
areaPtr
Print the value at
area
Ptr ont
o
the screen
Calculate the perimeter and store the result in the value at perimeterPtr
Print the value at perimeterPtr onto the screen
//the function has a void return type
Sample output:
PART 1:
Enter an integer: 4
The sum total is 30 and the product total is 576
PART 2:
You will be entering the length of the side of a square:
Enter an integer: 7
Inside the CalculateBothSquare funct
ion
The calculation results inside the CalculateBothSquare function:
The area is 49 and the perimeter is 28
The calculation results back inside the main function:
The area is 49 and the perimeter is 28
Press any key to continue . . .
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