Write program in C Given a double array called extraPoints with the size of the
ID: 3698609 • Letter: W
Question
Write program in C
Given a double array called extraPoints with the size of the array is 30.
Write the C code to perform the following steps:
Write a loop that initializes all the doubles in the array to 10.5.
Read a value from the keyboard into the first cell of the array. (remember to prompt )
Store the same value into the last cell of the array.
Store the same value into the next to last cell of the array.
Write a loop that totals all of the values in the array and displays the total onto the screen.
Declare and initialize all variables necessary.
Explanation / Answer
#include<stdio.h>
int main()
{
double extraPoints[30];
double total=0.0;
int i;
// a loop that initializes all the doubles in the array to 10.5.
for(i=0;i<=29;i++)
{
extraPoints[i]=10.5;
}
printf("Read a value from the keyboard into the first cell of the array : ");
scanf("%f",&extraPoints[0]);
//Store the same value into the last cell of the array
extraPoints[29]=extraPoints[0];
//Store the same value into the next to last cell of the array.
extraPoints[30]=extraPoints[0];
//loop that totals all of the values in the array
printf(" ");
for(i=0;i<=29;i++)
{
total=total+extraPoints[i];
}
//displays the total onto the screen
printf(" The total is %f ",total);
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.