Question
asap please
write a program that will: Have an array that can hold up to se0 Integers Put 30 random integers from e to 100 into spots 0-2
0 0
Add a comment Improve this question Transcribed image text
Answer #1

//since you have not given the programming language, I am doing it in C language. Programming logic remains same for c++, you can use same code if it is for c++

#include <stdio.h>
#include<time.h>
#include <stdlib.h>
#include<math.h>
#include<stdlib.h>

void print(int arr[], int n);
void sort(int arr[], int n);
void fillArray(int arr[], int n);
int findMin(int arr[], int n);
int findMax(int arr[], int n);
int findMode(int arr[], int n);
int range(int arr[], int n, int lower, int higher);
double findMean(int arr[], int n);
double stdDeviation(int arr[], int n, double mean);

int main(void) {
   double mean;
   int i;
   //declare an array with 500 elements
   int arr[500];
   fillArray(arr, 30);
   //print array
   printf("Original array is: ");
   print(arr, 30);
   //sort array
   sort(arr, 30);
   //print sorted array
   printf("\nSorted array is: ");
   print(arr, 30);
   printf("\nMax number is : %d\n", findMax(arr, 30));
   printf("Min number is : %d\n", findMin(arr, 30));
   mean = findMean(arr, 30);
   printf("Mean is %.2lf\n", mean);
   printf("Standard deviation is %.2lf\n", stdDeviation(arr, 30,mean));
   //range is in terms of 10 elements, ex 0-10, 11-20, 21-30
   printf("###Range####\n");
   for (i = 0; i < 100; i+=10)
   {
       printf("%d-%d: %d\n", i, i + 10, range(arr, 30, i, i+10));
   }
   return 0;
}

void print(int arr[], int n)
{
   int i;
   printf("Array is: ");
   for (i = 0; i < n; i++)
   {
       printf("%d ", arr[i]);
   }
}
void sort(int arr[], int n)
{
   int i, j, tmp;
   for (i = 0; i < n; i++)
   {
       for (j = 0; j <n-i-1; j++)
       {
           if (arr[j] >arr[j + 1])
           {
               tmp = arr[j];
               arr[j] = arr[j + 1];
               arr[j + 1] = tmp;
           }
       }
   }
}
void fillArray(int arr[], int n)
{
   int i;
   srand(time(NULL));
   for (i = 0; i < n; i++)
   {
       arr[i] = rand() % 100;
   }
}
int findMin(int arr[], int n)
{
   int min = arr[0], i;
   for (i = 0; i < n; i++)
   {
       if (min > arr[i])
       {
           min = arr[i];
       }
   }
   return min;
}
int findMax(int arr[], int n)
{
   int max = arr[0], i;
   for (i = 0; i < n; i++)
   {
       if (max < arr[i])
       {
           max = arr[i];
       }
   }
   return max;
}
int findMode(int arr[], int n)
{
   int m[100] = { 0 }, i, j, mode;

   for (i = 0; i < 100; i++)
   {
       for (j = 0; j<n; j++)
           if (arr[j] == i)
           {
               arr[i]++;
           }
   }
   mode = findMax(arr, n);
   return mode;
}

int range(int arr[], int n,int lower,int higher)
{
   int i,k=0;
   for (i = 0; i < n; i++)
   {
       if (arr[i] >= lower && arr[i] <= higher)
       {
           k++;
       }
      
   }
   return k;
}
double findMean(int arr[], int n)
{
   double sum = 0;
   int i;
   for (i = 0; i < n; i++)
   {
       sum += arr[i];
   }
   return (sum / n);
}
double stdDeviation(int arr[], int n, double mean)
{
   double sum = 0, std;
   int i;
   double m = findMean(arr, n);

   for (i = 0; i < n; i++)
   {
       sum += pow((arr[i] - mean), 2);
   }
   return sqrt((sum) / n);
}

/*Output
Original array is: Array is: 2 90 75 1 44 27 30 81 59 46 46 54 52 66 46 7 57 5 91 34 95 26 10 71 35 57 30 95 60 2
Sorted array is: Array is: 1 2 2 5 7 10 26 27 30 30 34 35 44 46 46 46 52 54 57 57 59 60 66 71 75 81 90 91 95 95
Max number is : 95
Min number is : 1
Mean is 46.47
Standard deviation is 28.57
###Range####
0-10: 6
10-20: 1
20-30: 4
30-40: 4
40-50: 4
50-60: 6
60-70: 2
70-80: 2
80-90: 2
90-100: 4

*/

Add a comment
Know the answer?
Add Answer to:
asap please write a program that will: Have an array that can hold up to se0...
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
  • (+30) Provide a python program which will Populate an array(list) of size 25 with integers in...

    (+30) Provide a python program which will Populate an array(list) of size 25 with integers in the range -100 (negative 100)   to +100 inclusive Display the array and its length (use the len function) Display the average of all the integers in the array Display the number of even integers (how many) Display the number of odd integers (how many) Display the number of integers > 0   (how many) Display the number of integers < 0   (how many) Display the...

  • Please write a Java program that does the following: Create an array of 100 integers. Store...

    Please write a Java program that does the following: Create an array of 100 integers. Store 100 random integers (between 1 and 100) in the array. Print out the elements of the array. Sort the array in ascending order. Print out the sorted array. Prompt the user to enter a number between 1 and 100. Search the array for that number and then display "Found" or "Not Found" message. Display each number from 1 to 100 and the number of...

  • Write a Java program with a single-dimension array that holds 11 integer numbers and sort the...

    Write a Java program with a single-dimension array that holds 11 integer numbers and sort the array using a bubble sort. Next, identify the median value of the 11 integers. Here are the steps your program must accomplish. algorithm (either flowchart or pseudocode) that you will use to write the program Step 1. Create an Place the algorithm in a Word document. 6. Ste the Step 2. Code the program in Eclipse and ensure the following steps are accomplished. 1....

  • For this c++ assignment, Overview write a program that will process two sets of numeric information....

    For this c++ assignment, Overview write a program that will process two sets of numeric information. The information will be needed for later processing, so it will be stored in two arrays that will be displayed, sorted, and displayed (again). One set of numeric information will be read from a file while the other will be randomly generated. The arrays that will be used in the assignment should be declared to hold a maximum of 50 double or float elements....

  • PROGRAM DESCRIPTION Using the given class definitions for either C++, create a minimum heap that stores...

    PROGRAM DESCRIPTION Using the given class definitions for either C++, create a minimum heap that stores integers and and implements a minimum priority queue. (Your program can be "hard coded" for integers - it does not need to use templates, generics, or polymorphism.) Your data structure must always store its internal data as a heap. Your toString function should return a string with the heap values as a comma separated list, also including the size of the heap as well....

  • Please!!! need help asap!!!! write a C++program to analyze a small subset of the data that...

    Please!!! need help asap!!!! write a C++program to analyze a small subset of the data that has been collected. See file universities.txt .Use precisely seven parallel arrays: one for name of university, one for state, one for city, one for yearly tuition, one for enrollment, one for average freshman retention, and one for the percent of students who graduate with in six years. Note that the percentage of student accepted is not stored.An output file is opened in main() and...

  • This is for C++ Write a program that reads in a sequence of characters entered by...

    This is for C++ Write a program that reads in a sequence of characters entered by the user and terminated by a period ('.'). Your program should allow the user to enter multiple lines of input by pressing the enter key at the end of each line. The program should print out a frequency table, sorted in decreasing order by number of occurences, listing each letter that ocurred along with the number of times it occured. All non-alphabetic characters must...

  • Need C programming help. I've started to work on the program, however I struggle when using...

    Need C programming help. I've started to work on the program, however I struggle when using files and pointers. Any help is appreciated as I am having a hard time comleting this code. #include <stdio.h> #include <stdlib.h> #include <string.h> #define MAX_LINE 100 #define MAX_NAME 30 int countLinesInFile(FILE* fPtr); int findPlayerByName(char** names, char* target, int size); int findMVP(int* goals, int* assists, int size); void printPlayers(int* goals, int* assists, char** names, int size); void allocateMemory(int** goals, int** assists, char*** names, int size);...

  • USE THE PYTHON ONLY Sudoku Game Check Please write a Python program to check a Sudoku...

    USE THE PYTHON ONLY Sudoku Game Check Please write a Python program to check a Sudoku game and show its result in detail. This is an application program of using 2-dimensional arrays or lists. Each array or list is a game board of 9 x 9. Your program must check the 9 x 9 game board, and report all the problems among 9 rows, 9 columns, and 9 squares. As you can see, you must pre-load the following four games...

  • in c++ please program for this code #include <iostream> #include <fstream> #include <string> #include <cstring> //...

    in c++ please program for this code #include <iostream> #include <fstream> #include <string> #include <cstring> // for string tokenizer and c-style string processing #include <algorithm> // max function #include <stdlib.h> #include <time.h> using namespace std; // Extend the code here as needed class BTNode{ private: int nodeid; int data; int levelNum; BTNode* leftChildPtr; BTNode* rightChildPtr; public: BTNode(){} void setNodeId(int id){ nodeid = id; } int getNodeId(){ return nodeid; } void setData(int d){ data = d; } int getData(){ return data;...

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