Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

#include<stdio.h> #include<math.h> //declaring function prototypes void fillArra

ID: 662539 • Letter: #

Question

#include<stdio.h>
#include<math.h>
//declaring function prototypes
void fillArray(int *arr[],int size);
int calculateMean(int *arr[],int size);
int calculateDeviation(int *arr[], int size,double mean);
int main()
{
int *arr[15];
int n,i;
double mean,deviation;
printf("How many numbers you want to enter: ");
scanf("%d",&n); //reading input from user..how many numbers want to enter
fillArray(&arr,n); //calling function to initialize array
printf(" Entered numbers are: ");
for(i=0;i<n;i++){
printf(" %d",arr[i]); //printing enetered numbers
}
printf(" calculating Mean Now");
mean = calculateMean(&arr,n);//function to calcualte mean
printf(" Calculated Mean = %f",mean);
deviation = calculateDeviation(&arr,n,mean); //function to calculate deviation
printf(" Calculated deviation = %f",deviation);
return 0;
}
void fillArray(int *arr[],int size){
int i;
for(i=0;i<size;i++){
printf("Enter number");
scanf("%d", &arr[i]); //initializing array
}
}
int calculateMean(int *arr[],int size){ //calculating mean...total/size
int i;
int sum=0,val;
for(i=0;i<=size;i++){
val=arr[i];
sum=sum+val;
}
return sum/size;
}
int calculateDeviation(int *arr[], int size,double mean){//calculating deviation...
int i,val;
double deviation;
for(i=0;i<size;i++)
{
val = arr[i];
deviation+=(val-mean)*(val-mean);
}
deviation = deviation/size;
return sqrt(deviation); //using square root predefined function...math.h library
}

Question 4: (20 marks) Consider a sequence of floating point number, xi,i = 1,2, , m. The mean is defined as: x = (x1 + X2+, , +x,n)/m The deviation about the mean is di = Xi-i and the standard deviation is Solve this question with pointer Write a complete C program to () Define a function read 0 to read in the m elements of a one dimensional floating point i) Define functions sum), mean0 and deviation0, compute the sum of these elements, ii) Use the program to process the following set of data: array the mean the deviation, and the standard deviation, respectively 27.5 13.4 53.8 29.2 74.5 87.0 39.9 47.7 8.1 63.2

Explanation / Answer

your code looks fine but some problems are there:
1) type casting and
2)sqrt() which is predefined method
so you can add a option -lm while compiling your code.
typecast in calculateDeviation method and calculateMean methods
you are assigining pointer to int.
(val = arr[i];)
here is the code to find deviation:

compile with option -lm

#include <stdio.h>
#include <math.h>
float standard_deviation(float data[], int n);
int main()
{
    int n, i;
    float data[100];
    printf("Enter number of elements ");
    scanf("%d",&n);
    printf("Enter elements: ");
    for(i=0; i<n; ++i)
        scanf("%f",&data[i]);
    printf(" ");
    printf("Standard Deviation = %.2f", standard_deviation(data,n));
    return 0;
}
float standard_deviation(float data[], int n)
{
    float mean=0.0, sum_deviation=0.0;
    int i;
    for(i=0; i<n;++i)
    {
        mean+=data[i];
    }
    mean=mean/n;
    for(i=0; i<n;++i)
    sum_deviation+=(data[i]-mean)*(data[i]-mean);
    return sqrt(sum_deviation/n);         
}

OUTPUT:
Enter number of elements 4
23
34
12
20
Standard Deviation = 7.89