Question
Please read entire post Part 1 Modify the code below so that it uses heap memory to store percentage grades in the range from 0
Please read entire post
Part 1
Modify the code below so that it uses heap memory to store percentage grades in the range from 0 to 100 (inclusive). The program should allow the user to indicate when he or she is done entering grades (since the user may not have grades to fill the whole array). When the user is done entering grades, the program should print out the grades entered by the user. Be sure to free the head memory before the program ends.
Part 2:
Modify the below code from so that it uses custom functions to add grades to the array, print the grades entered, calculate the average grade (arithmetic mean, not letter grade), and report the highest and lowest grade entered. This version of the program does not need to use heap memory, though you are welcome to do so. The program should allow the user to indicate when he or she is done entering grades (since the user may not have grades to fill the whole array). When the user is done entering grades, the program should print out the grades entered by the user. The program should also display the average grade, highest grade, and lowest grade.
#include "stdio.h"
int main(void)
{
//initialize array
int arr[100];
//initialize variables
int i=0, j=0, n=0;
//infinite loop which will stop when user enters -1
while(n != -1)
{
printf("Enter percentage grade(0-100). Enter -1 to stop: ");
//read grade
scanf("%d",&n);
//if user entered grade is not -1
if(n != -1)
{
//save it to array
arr[i++] = n;
}
//if user entered -1, then exit this loop
else
{
break;
}
}
printf(" The grades are: ");
//loop which will iterate till no:of user entered grades
for(j=0; j
{
//print the grade
printf("%d ",arr[j]);
}
return 0;
}
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