If you have any doubts, please give me comment...
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
#define MAX_SIZE 500
void printArray(int array[], int numElements, int numPerLine, ostream &os);
void printDivBy(int array[], int numElements, int numPerLine, int divBy, ostream &os);
void maxMinNextValues(int array[], int numElements, int &max, int &max_next, int &min, int &min_next);
int sumOfValues(int array[], int numElements);
int main(){
int array[MAX_SIZE];
for(int i=0; i<MAX_SIZE; i++)
array[i] = (rand()%21)-10;
cout<<"Array Values: "<<endl;
printArray(array, MAX_SIZE, 8, cout);
cout<<endl;
cout<<"Division by 3 values are: "<<endl;
printDivBy(array, MAX_SIZE, 5, 3, cout);
cout<<endl;
int max, max_next, min, min_next;
maxMinNextValues(array, MAX_SIZE, max, max_next, min, min_next);
cout<<"Max: "<<max<<"\nMax Next: "<<max_next<<endl;
cout<<"Min: "<<max<<"\nMin Next: "<<min_next<<endl;
int sum = sumOfValues(array, MAX_SIZE);
cout<<"Sum of values are: "<<sum<<endl;
cout<<"Average of values is: "<<((double)sum/MAX_SIZE)<<endl;
return 0;
}
void printArray(int array[], int numElements, int numPerLine, ostream &os){
for(int i=0; i<numElements; i++){
os<<array[i]<<"\t";
if((i+1)%numPerLine==0)
os<<endl;
}
}
void printDivBy(int array[], int numElements, int numPerLine, int divBy, ostream &os){
int j=0;
for(int i=0; i<numElements; i++){
if(array[i]%divBy==0){
os<<array[i]<<"\t";
j++;
if(j%numPerLine==0)
os<<endl;
}
}
}
void maxMinNextValues(int array[], int numElements, int &max, int &max_next, int &min, int &min_next){
int max_ind = 0, min_ind = 0;
for(int i=0; i<numElements; i++){
if(array[max_ind]<array[i])
max_ind = i;
if(array[min_ind]>array[i])
min_ind = i;
}
max = array[max_ind];
max_next = array[max_ind+1];
min = array[min_ind];
min_next = array[min_ind+1];
}
int sumOfValues(int array[], int numElements){
int sum = 0;
for(int i=0; i<numElements; i++){
sum += array[i];
}
return sum;
}
Create a program that creates an array of 500 random numbers between -10 and 10. Write...
Write a program in C that creates an array of 100 random numbers from 0-99. The program sums the random numbers and prints the sum. It then writes the numbers to a new file using open, close and write. Then looks in the current directory for files that match the pattern “numbers.XXXX”. For each file, open the file and read the file. You can assume that the file will contain 100 integers. Sum the integers. Print the filename and the sum...
I need a c++ code please. 32. Program. Write a program that creates an integer constant called SIZE and initialize to the size of the array you will be creating. Use this constant throughout your functions you will implement for the next parts and your main program. Also, in your main program create an integer array called numbers and initialize it with the following values (Please see demo program below): 68, 100, 43, 58, 76, 72, 46, 55, 92, 94,...
***Please complete the code in
C***
Write a program testArray.c to initialize an array by getting user's input. Then it prints out the minimum, maximum and average of this array. The framework of testArrav.c has been given like below Sample output: Enter 6 numbers: 11 12 4 90 1-1 Min:-1 Max:90 Average:19.50 #include<stdio.h> // Write the declaration of function processArray int main) I int arrI6]i int min-0,max-0 double avg=0; * Write the statements to get user's input and initialize the...
need help editing or rewriting java code, I have this program
running that creates random numbers and finds min, max, median ect.
from a group of numbers,array. I need to use a data class and a
constructor to run the code instead of how I have it written right
now. this is an example of what i'm being asked
for.
This is my code:
import java.util.Random;
import java.util.Scanner;
public class RandomArray {
// method to find the minimum number in...
Write a C Program that inputs an array of integers from the user along-with the length of array. The program then prints out the array of integers in reverse. (You do not need to change (re-assign) the elements in the array, only print the array in reverse.) The program uses a function call with array passed as call by reference. Part of the Program has been given here. You need to complete the Program by writing the function. #include<stdio.h> void...
Write a program that initializes an array with ten random integers and then prints out the following: Every element at an even index; Every even element All elements in reverse order; Only the first and last elements; The minimum and maximum element The sum of all elements The alternating sum of all elements, where the alternating sum contains all elements at even index added, and the elements at odd index subtracted. Please write comments above the piece of code that...
Write a program that will do the following. The main function should ask the user how many numbers it will read in. It will then create an array of that size. Next, it will call a function that will read in the numbers and fill the array (fillArray). Pass the array that was made in themain function as a parameter to this function. Use a loop that will read numbers from the keyboard and store them in the array. This...
Write a C++ program that simulates playing the Powerball game. The program will generate random numbers to simulate the lottery terminal generated numbers for white balls and red Powerball. The user will have the option to self-pick the numbers for the balls or let the computer randomly generate them. Set the Grand Prize to $1,000,000,000.00 in the program. Project Specifications Input for this project: Game mode choice – self pick or auto pick Five numbers between 1 and 69 for...
Write a C program convert.c that converts each number in an array by the sum of that number plus 6 modulus 10. A sample input/output: Enter the length of the array: 5 Enter the elements of the array: 3 928 4 14 77 Output: 9 4 0 0 3 The program should include the following function: void convert(int *a1, int n, int *a2) The function converts every element in array a1 of length n to an output array a2. The...
Write a JAVA program with methods that initializes an array with 20 random integers between 1 and 50 and then prints four lines of output, containing 1)The initialized array. 2)Every element at an even index. 3)Every even element. 4)All elements in reverse order. Requirements (and hints): 1. Build a method that takes any integer array as input and prints the elements of the array. ALL printing in this lab must be done using a call to the printArray method and...