Code: (as the array contains random numbers, output will differ at every run)
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int gcd(int a, int b)
{
if (a == 0)
return b;
return gcd(b % a, a);
}
int findGCD(int arr[], int n)
{
int result = arr[0];
for (int i = 1; i < n; i++)
result = gcd(arr[i], result);
return result;
}
int index(int num){
if(num<61) return 0;
else if(num<71) return 1;
else if(num<75) return 2;
else return 3;
}
int main()
{
char category[4][10] = {"short ", "average ", "tall ", "big
"};
int random_numbers[100];
int scale[4] = { 0, 0, 0, 0 };
int i, temp, gcd;
srand(time(0));
for (i = 0; i < 100; i++) {
temp = (rand() % (37)) + 48;
random_numbers[i] = temp;
scale[index(temp)]++;
}
gcd = findGCD(scale, 4);
for(i = 0; i < 4; i++){
scale[i]/=gcd;
cout<<category[i];
while(scale[i]--){
cout<<'*';
}
cout<<'\n';
}
return 0;
}
Output:
C++ 2) Create a program that does all of the following: Create 100 random int numbers...
C++ Program Int Main First Please Write one program that does the following: 1. 1. Ask the user for ten (10) grades, and store the data in an array. Compute the average of all the grades. Print the original ten grades and the average. a. Declare an integer array with the name of “grades” of size 10 in the main function. b. Create a function called “getGrades” that prompts the User for the grades and puts them in an integer array. i. The function will receive...
The ExceptionLab class provided: – Creates an array of 100 elements and fills it with random numbers from 1 to 100. – It asks the user for an index value between 0 and 99. – Prints the element at that position. – If a number > 99 is entered by the user, the class will abort with an ArrayIndexOutOfBoundsException • Modify the ExceptionLab: – Add a try-catch clause which intercepts the ArrayIndexOutOfBounds and prints the message: Index value cannot be...
Write a program that writes a series of random numbers to a file. Each random number should be in the range of 1 through 500 inclusive. 1.Use a file called randoms.txt as a input file and output file a. If you go to open the file and its not there then ask the user to create the file and then quit 2. Ask the user to specify how many random numbers the file will hold. a.Make sure that the...
Count Below and Above Average Numbers Use the following main( ) function: const int maxSize = 50; int main() { int l, u, n, A[maxSize], le, mo; input(l, u); cout << "How many numbers you want to generate < 50: "; cin >> n; generateNumbers(n, l, u, A); le = countLessMore(n, A, mo); cout << "There are " << le << " numbers less than the average and " << mo << " numbers more than the average" <<...
In C plus plus Objective: Create an array of numbers based upon user input. Program logic: Ask the user for how big to size the array. Create an array based upon that size. Ask for a number, add that number to the array. Repeat adding to the end until all numbers have been entered or until they enter -1 for the number. Print the list.
Write a program named Remainder.java then implement the following method: public static int divisibleBy(int[] arr, int M, int K) this method determines the number of elements in the int array (arr) that are divisible by M but not K. Then write code inside main method to test your method: your main method accepts three numbers from the command argument list, N, M, K, use the first number to create int array with size of N, assign random number between 0...
DESCRIPTION Implement a program in C++ that generates a specified number of random integers, records them in three arrays, then sorts the arrays with Insertion Sort, Merge Sort, and Quick Sort, respectively. Augment the three sorting algorithms with counters and report the number of characteristic operations each performs in sorting the (same) random values. INPUT The program reads from the terminal the number of random integers to generate, a seed value for the pseudo-random number generator, and a character that...
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 C++ program named, gradeProcessor.cpp, that will do the following tasks: -Print welcome message -Generate the number of test scores the user enters; have scores fall into a normal distribution for grades -Display all of the generated scores - no more than 10 per line -Calculate and display the average of all scores -Find and display the number of scores above the overall average (previous output) -Find and display the letter grade that corresponds to the average above (overall...
Write a simple Java program with the following naming structure: Open Eclipse Create a workspace called hw1 Create a project called hw1 (make sure you select the “Use project folder as root for sources and class files”) Create a class called Hw1 in the hw1 package (make sure you check the box that auto creates the main method). Add a comment to the main that includes your name Write code that demonstrates the use of each of the following basic...