This is C Programming: I have the following code that I am working on an need as
ID: 3600723 • Letter: T
Question
This is C Programming:
I have the following code that I am working on an need assistnace on the following implementation of code for this part:
Your assistance would be greatly appreciated.
Thank you
This is my code:
These are the instructions, were told we do need to copy a string, create a temporary string of size 1024 or 248 characters and copy the original string into thei temporary string using the strcpy function from string.h.
This code he provided as a hint on how to create the code above:
This is the output:
19 20 21 #include 23 24 int main (int argc, char* argv) 25 { 26 27 28 int size, i; char order:Explanation / Answer
#include <stdio.h>
float get_average(float array[],int size){
float sum = 0;
int i;
for (i = 0; i<size; i++){
sum = sum + array[i];
}
return (sum/size);
}
float get_variance(float array[],int size){
float sum = 0;
int i;
float avg;
for (i = 0; i<size; i++){
sum = sum + array[i];
}
avg = sum/size;
sum = 0;
for (i = 0; i<size; i++){
sum = sum + (array[i]-avg) * (array[i]-avg) ;
}
float var = sum/size;
return var;
}
float get_min(float array[],int size){
float min = array[0];
int i;
for (i = 0; i<size; i++){
if (min > array[i])
min = array[i];
}
return min;
}
float get_max(float array[],int size){
float max = array[0];
int i;
for (i = 0; i<size; i++){
if (max < array[i])
max = array[i];
}
return max;
}
float get_median(float array[],int size){
int i,j;
float temp;
float val;
for (i = 0; i<size; i++){
for (j = i+1; j<size; j++){
if (array[i] > array[j]){
temp = array[i];
array[i] = array[j];
array[j] = temp;
}
}
}
if (size % 2 == 0){
val = (array[size/2 -1] + array[size/2])/2;
return val;
}
else {
return array[size/2];
}
}
int main(int argc , char *argv[]){
float data[100];
int count;
int i;
count = argc - 1;
for (i = 1; i<argc; i++){
data[i-1] = atof(argv[i]);
}
float mean = get_average(data,count);
float variance = get_variance(data,count);
float min = get_min(data,count);
float max = get_max(data,count);
float median = get_median(data,count);
for (i = 0; i<count; i++){
printf("%f ", data[i]);
}
printf(" ");
printf("%d %f %f %f %f %f ",count,median,min,max,mean,variance);
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.