THIS IS MY CODE. I NEED HELP FILLING IN THE BLANKS PLEASE #include <stdio.h> #in
ID: 3589694 • Letter: T
Question
THIS IS MY CODE. I NEED HELP FILLING IN THE BLANKS PLEASE
#include <stdio.h>
#include <stdbool.h> // library that defines the bool, true, and false keywords
// function that will sum up the values in an array
double sum( double theArray[], int theArraySize )
{
double theSum = 0; // we'll store the sum here
// iterate thru all values in theArray
for( int x = 0; x < theArraySize; x++ ){
// add the next value to theSum
theSum += theArray[ x ];
}
return theSum; // give back the value of theSum
}
// function that will find the average value of an array
double average( double theArray[], int theArraySize )
{
// put your code here
double theSum = 0; //stores the sum
//goes through all the values in the array
for( int x = 0; x < theArraySize; x++ ){
theSum += theArray[ x ];
}
return theSum / theArraySize; //give back the average value of the array by dividing the sum and array size
}
// function that will find the standard deviation of an array
// stdev
// put your code here
// function that will determine whether a value is odd or even
bool isOdd( int theValue )
{
// put your code here
}
// function that will determine whether a value is prime or not
bool isPrime( int theValue )
{
// put your code here
}
int main()
{
// prompt the user for 10 numeric values, store them in an array,
// and then display the sum, average, and standard deviation to the user
// Then ask for an integer, and tell the user whether it is odd/even, prime/composite.
return 0;
}
Explanation / Answer
#include <stdio.h>
#include <math.h>
#include <stdbool.h> // library that defines the bool, true, and false keywords
// function that will sum up the values in an array
double sum( double theArray[], int theArraySize )
{
double theSum = 0; // we'll store the sum here
// iterate thru all values in theArray
for( int x = 0; x < theArraySize; x++ ){
// add the next value to theSum
theSum += theArray[ x ];
}
return theSum; // give back the value of theSum
}
// function that will find the average value of an array
double average( double theArray[], int theArraySize )
{
// put your code here
double theSum = 0; //stores the sum
//goes through all the values in the array
for( int x = 0; x < theArraySize; x++ ){
theSum += theArray[ x ];
}
return theSum / theArraySize; //give back the average value of the array by dividing the sum and array size
}
// function that will find the standard deviation of an array
// stdev
// put your code here
// function that will determine whether a value is odd or even
bool isOdd( int theValue )
{
// put your code here
if(theValue % 2 == 1){
return true;
}
return false;
}
// function that will determine whether a value is prime or not
bool isPrime( int theValue )
{
int f;
// put your code here
for ( f = 2; f <= theValue / 2; f++) {
if (theValue % f == 0) {
return false;
}
}
return true;
}
int main()
{
// prompt the user for 10 numeric values, store them in an array,
double a[10], avg, standardDeviation=0;
int i,n;
printf("Enter 10 values: ");
for(i=0;i<10;i++) {
scanf("%lf", &a[i]);
}
avg = average(a, 10);
for(i = 0; i < 10; ++i)
standardDeviation += pow(a[i] - avg, 2);
// and then display the sum, average, and standard deviation to the user
printf("Sum = %lf ", sum(a, 10));
printf("Average = %lf ",avg );
printf("standard deviation = %lf ", standardDeviation);
// Then ask for an integer, and tell the user whether it is odd/even, prime/composite.
printf("Enter the number: ");
scanf("%d", &n);
printf("Is Odd: %d ", isOdd(n));
printf("isPrime: %d ", isPrime(n));
return 0;
}
Output:
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.