Question

C++ ProgrammeWrite a function that receives, as arguments, a pointer to a double array, as well as the number of elements: in the array(in

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Please find the required C++ script as the following:

//========================================================

#include <iostream>

#include <iomanip> // For controlling double precision

#include <math.h>

using namespace std;

#define size 10

double stdDev(double* arr,int arr_size)

{

int i;

double sum_n=0,sum_n2=0,std_val;

for(i=0;i<arr_size;i++)

{

sum_n=sum_n+arr[i]; // Calculating sum(xi)

sum_n2=sum_n2+(arr[i]*arr[i]); // Calculating sum(xi^2)

}

std_val = sqrt((sum_n2/arr_size)-pow(sum_n/arr_size,2));

return std_val;

}

int main() {

// Input array

double arr[size] = {11.2,2.4,3.13,16.4,5.8,9.22,4.9,10.5,6.5,2.99};

// Function call and output

cout <<setprecision(7)<<"Standard Deviation: "<<stdDev(arr,size)<<"\n";

return 1;

}

//===================================================

output:

Standard Deviation: 4.249367

Hope this helps!

************* PLEASE THUMBS UP!!!!!!!!!!! *************

In case of any clarification, please comment!

Add a comment
Know the answer?
Add Answer to:
C++ Programme Write a function that receives, as arguments, a pointer to a double array, as...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT