..1 Verizon 1:30 PM @* 42% mycourses.purdue.edu CNIT105-INLAB08 Due: By the end
ID: 3726075 • Letter: #
Question
..1 Verizon 1:30 PM @* 42% mycourses.purdue.edu CNIT105-INLAB08 Due: By the end of the lab session Objectives: Parallel Arrays Sequential Search Named Constant: Define a named constant. SIZE = 20 for size of array Write the code in the main function to do the following tasks: 1. Declare an array to store up to 20 scores-whole numbers. 2. Partially fill the arrays in a loop-use score to end the data entry. 3. Display the number of entries in the array. . Write a loop to display array score to the 5. Compute the average score - display it to the screen. 6. Use sequential search to display all the scores >= 70. a. Inform the user if search fails. 7, Use sequential search to find the unique score = 100. a. Inform the user if search fails. Eudent wishExplanation / Answer
PLEASE REFER BELOW CODE
#include<stdlib.h>
#include<stdio.h>
#define SIZE 20 //given named constant SIZE 20
int main()
{
int arr[SIZE]; //declaring array of size 20
int i,j,flag=0;
float avg=0.0;
//given first two lines in output widow
printf("************************************* ");
printf("In Lab08 Solution ");
printf("By: Shaocheng Lao ");
printf(" ************************************* ");
//partially fill the array in loop and -1 to terminate data entry
for(i = 0; i < SIZE; i++)
{
printf("Enter Student's score: ");
scanf("%d", &arr[i]);
if(arr[i] == -1)
break;
}
//displaying number of entries in array
printf(" Number of entries = %d ", i);
//displaying array score to screen
printf("Score ");
printf("************************************* ");
for(j = 0; j < i;j++)
{
printf("%d ", arr[j]);
avg += arr[j];
}
//computing average score and display on screen
avg = avg / i;
printf(" The average score is %.2f ", avg);
//displaying score >=70 and informing user if fails
printf("Scores >= 70 are ");
for(j = 0; j < i; j++)
{
if(arr[j] >= 70)
{
printf("%d ", arr[j]);
flag = 1;
}
}
if(!flag)
printf("Not found score >= 70 ");
flag = 0;
//sequential search to find unique score 100 and display message if fails
for(j = 0; j < i; j++)
{
if(arr[j] == 100)
{
printf(" Student with score = 100 was found ");
flag = 1;
break;
}
}
if(!flag)
printf("Not found score == 100 ");
return 0;
}
PLEASE REFER BELOW OUTPUT
*************************************
In Lab08 Solution
By: Shaocheng Lao
*************************************
Enter Student's score: 23
Enter Student's score: 56
Enter Student's score: 71
Enter Student's score: 91
Enter Student's score: 100
Enter Student's score: -1
Number of entries = 5
Score
*************************************
23
56
71
91
100
The average score is 68.20
Scores >= 70 are
71
91
100
Student with score = 100 was found
Process returned 0 (0x0) execution time : 13.414 s
Press any key to continue.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.