Question: i am getting a segmentation when my array is above 5 and dont know what is cause it here is my code(coding in C): #include
i am getting a segmentation when my array is above 5 and dont know what is cause it
here is my code(coding in C):
#include
int main()
{
int size; /* size of the array */
int grades[size]; /* grades inputed by user */
int count; /* array position count */
double avg; /* average grade of the class */
int fail; /* number of failing grades */
double sum;
size = 0;
/*
* Asks the user the number of grades they would like to input
*/
printf("How many grades would you like to input today? ");
scanf("%d", &size);
/*
* Ask user to input grades
*/
for (count = 0; count < size; count++)
{
printf("Please enter each grade one by one: ");
scanf("%d", &grades[count]);
}
/*
* Finds the average of the grades that the user inputs
*/
for (count = 0; count < size; count++)
{
sum = sum + grades[count];
avg = sum/size;
}
printf("The average grade is %.2lf ", avg);
/*
* Calculates the number of failing grades
*/
for (count = 0; count < size; count++)
{
while (grades[count] < 70)
{
fail++;
break;
}
}
printf("The number of failing grades is %d ", fail);
return 0;
}
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
