Using C++
And
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
a) Write a main function and declare an array with 100 elements.
b) In the main, initialize each number in the array to be a random number between 100 and 200.
c) Write a function that returns the value of the smallest number in the array. Call this function from the main and print the result.
d) Declare a 2D array with dimensions 2x2 and initilize the array, as follows:
[1, 2;
3, 4]
#include <stdio.h> #include <stdlib.h> #include <time.h> // Write a function that returns the value of the smallest number in the array. int smallest(int arr[], int size) { int min = arr[0]; for (int i = 0; i < size; ++i) { if (arr[i] < min) { min = arr[i]; } } return min; } int main() { srand(time(NULL)); // a) Write a main function and declare an array with 100 elements. int arr[100], i; // b) In the main, initialize each number in the array to be a random number between 100 and 200. for (i = 0; i < 100; ++i) { arr[i] = 100 + (rand() % 101); } // c) Call this function from the main and print the result. printf("%d\n", smallest(arr, 100)); // d) Declare a 2D array with dimensions 2x2 and initialize the array, as follows int matrix[2][2] = {{1, 2}, {3, 4}}; return 0; }
Using C++ And #include <stdio.h> #include <stdlib.h> #include <time.h> a) Write a main function and declare...
Complete the program below in C please #include <stdio.h> #inlcude <stdlib.h> #include <time.h> typedef struct { int points; int strength; } Hero; /* print out the hero given by the parameter */ void printHero( ... ) { . . } void main() { Hero heroA, heroB; /* initialize both heroes to your choice of values */ . /* Pick one hero using rand(). Print out that hero */ . }
sort.c #include <stdlib.h> #include <stdio.h> #include "libsort.h" int main() { int* array; int size, c; float median; printf("Enter the array size:\n"); scanf("%d", &size); array = (int*) malloc(size * sizeof(int)); printf("Enter %d integers:\n", size); for (c = 0; c < size; c++) scanf("%d", &array[c]); sort(array, size); printf("Array sorted in ascending order:\n"); for (c = 0; c < size; c++) printf("%d ", array[c]); printf("\n"); median = find_median(array,...
computers. 1. How many times will this loop repeat? include <stdlib.h> #include <stdio.h> void main(void) int 10 for(= 0; i < 101) printf("d", 1); A. 10 times B. 1 time C. It will run forever D. 0 times 2. What will be the output of this program? #include <stdlib.h> #include <stdio.h> int main() int a = 100, b = 200, C = 300; if(!a >= 500) b = 300; C = 400; printf("%d, 8d, &d", a, b, c); return 0;...
#include<stdio.h> #include<stdlib.h> #include <time.h> int main() { /* first you have to let the computer generate a random number. Then it has to declare how many tries the user has for the game loop. we then need the player to enter their guess. After every guess we have to give an output of how many numbers they have in the right location and how many they have the right number. The player will keep guessing until their 10 tries are...
*Answer must be in C* Write a complete program as follows (declare any necessary variables): Create an array of doubles named “hummus” with 2 rows and 300 columns. Initialize all array elements to zero. Write a loop that will repeatedly ask the user to enter a value and store it in the first row of the array (do not overwrite previously entered values) until the whole first row is populated with the user input. (hint the loop should have the...
C++ Can someone please help with this code... even when the players number isnt a winning number the program always says the player wins: #include <stdio.h> #include <time.h> //main function int main() { //seeding a random number srand(time(0)); //define the arrays for the wagered, winning amount, percent amount double amounts[7] = { 1, 5, 10, 20, 50, 100, 1000 }; double payoff[7] = { 100, 500, 1000, 2000, 5000, 10000, 100000 }; double percent[7] = { 0.01, 0.05, 1, 2,...
Use the C programming language to complete #include <stdio.h> #include <stdlib.h> #include <float.h> // Declare Global variables here. void array_stats() { // Insert your solution here. } #include <stdlib.h> #include <time.h> int main() { // Simulate the test setup process. srand( time( NULL ) ); for ( int i = 0; i < 32; i++ ) { val[i] = rand(); } val_count = rand(); val_mean = rand(); val_min = rand(); val_max = rand(); // Call submitted code. array_stats(); // Display...
C Programming #include <stdio.h> #include <stdlib.h> #include <time.h> // These defines do a text replacement // everytime the string 'ROWS' and 'COLUMNS' // are found in this specific source file. // You can play with these values. #define ROWS 5 #define COLUMNS 5 /* ============= Tutorial on Graph format ============ You are given a randomly generated graph that looks of the form: 0 0 1 1 1 1 0 0 1 1 0 1 0 1 1 1 0 0...
Use C: 3. In function main, declare a two-dimensional integer array with 5 rows and 4 columns. Call the following functions from function main. Call a function createArray to seed the random number generator and to fill the two-dimensional array with random integers between -20 and +20. Parameters for this function should be the array and the number of rows and columns). Call a function signs to count the number of positive values, number of negative values and number of...
#include <assert.h> #include <stdio.h> #include <stdlib.h> // initialize_array is given an array "arr" of "n" elements. // It initializes the array by setting all elements to be "true" (any non-zero value). void initialize_array(int *arr, int n) { // TODO: Your code here. assert(0); } // mark_multiples is given an array "arr" of size n and a (prime) number "p" less than "n" // It assigns "false" (the zero value) to elements at array indexes 2*p, 3*p, 4*p,.., x*p (where x*p...