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

please write the program in C language. Statistical Analysis (Paired Programming

ID: 3847776 • Letter: P

Question


please write the program in C language.

Statistical Analysis (Paired Programming Project) write a program that creates an array of 10 integers, The program should then use the following functions getDatal Used to ask the user for the numbers and store them into an array displayData Used to display the data in the array. sortDataI Used to display the data in the array display areest0 used to find and display the largest number in the array. displaysmallestD Used to find and display the smalles number in the array. display Average used to find and display the average of the numbers in the array. display Rangel) Used to find and display the range of numbers in the array. You may not use any global variables. You must use a defined constant (udefine MAx 10 and use this constant in your code Show Me

Explanation / Answer

Code:
#include <stdio.h>

#define MAX 10

/*
Program to perform various functions on a given set of 10 integer numbers
Proram Name: createArr.c
*/

/* function declaration */
void getData(int[], int);
void displayData(int[], int);
void sortData(int[], int);
int displayLargest(int[], int);
int displaySmallest(int[], int);
double displayAverage(int[], int);
void displayRange(int[], int);

int main()
{
   int array[MAX];
   int max_num, min_num;
   double avg;

   getData(array, MAX);
   displayData(array, MAX);
   sortData(array, MAX);
   max_num = displayLargest(array, MAX);
   min_num = displaySmallest(array, MAX);
   printf(" Maximum number is : %d", max_num);
   printf(" Minimum number is : %d", min_num);
   avg = displayAverage(array, MAX);
   printf(" Average of given numbers is : %f", avg);
   displayRange(array, MAX);
   printf(" ");
   return 0;
}

/* function to read data from user into the array */
void getData(int a[], int n)
{
   int i;

   printf(" Enter the ten integer elements: ");
   for(i = 0; i < n; i++) {
       printf(" Enter %d number: ", i+1);
       scanf("%d", &a[i]);
   }
}

/* function to display data in the array */
void displayData(int a[], int n)
{
   int i;

   printf(" Given elements in array are: ");  
   for(i = 0; i < n; i++)
       printf(" %d", a[i]);
   printf(" ");
}

/* function to sort data in the array */
void sortData(int a[], int n)
{
   int i, j, temp;

   for(int i = 0; i < n; i++){
                for(int j = 0; j < n-1; j++)
                        if(a[j] > a[j+1]){
                                temp = a[j];
                                a[j] = a[j+1];
                                a[j+1] = temp;
                        }
   }
   printf(" Array elements after sorting are: ");
   for(i = 0; i < n; i++)
                printf(" %d", a[i]);

}

/* function to determine largest in the given elements */
int displayLargest(int a[], int n)
{
   int i, max;

   /* assigning the first element to max variable */
   max = a[0];
   /* iterating over loop and identifying max out of given numbers */
   for(i = 1; i < n; i++)
       if(a[i] > max)
           max = a[i];

   return max;
}

/* function to determine smallest in the given elements */
int displaySmallest(int a[], int n)
{
        int i, min;

        /* assigning the first element to min variable */
        min = a[0];
        /* iterating over loop and identifying min out of given numbers */
        for(i = 1; i < n; i++)
                if(a[i] < min)
                        min = a[i];
      
        return min;
}

/* function to obtain average out of the given elements */
double displayAverage(int a[], int n)
{
   int i;
   double sum = 0, average;
  
   /* calculating sum of all the elements */
   for(i = 0; i < n; i++)
       sum += a[i];
   /* determining average below */
   average = sum / n;

   return average;
}

/* function to display range of numbers in the given elements */
void displayRange(int a[], int n)
{  
   int high, low, i;

   /* initializaing high and low variables to the first element */
   high = low = a[0];
   /* iterating over array elements to determine the low and highest number for the range */
   for(i = 0; i < n; i++){
       if(a[i] > high)
           high = a[i];
       if(a[i] < low)
           low = a[i];
   }
   printf(" Given elements are from %d to %d range", low, high);
}


Execution and output:
Unix Terminal> ./a.out

Enter the ten integer elements:

Enter 1 number: 10

Enter 2 number: 78

Enter 3 number: 96

Enter 4 number: 24

Enter 5 number: 123

Enter 6 number: 988

Enter 7 number: 276

Enter 8 number: 1234

Enter 9 number: 2000

Enter 10 number: 19

Given elements in array are:

10
78
96
24
123
988
276
1234
2000
19

Array elements after sorting are:

10
19
24
78
96
123
276
988
1234
2000
Maximum number is : 2000
Minimum number is : 10
Average of given numbers is : 484.800000
Given elements are from 10 to 2000 range