Question

Using C++ And #include <stdio.h> #include <stdlib.h> #include <time.h> a) Write a main function and declare...

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]

0 0
Add a comment Improve this question Transcribed image text
Answer #1
#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;
}
Add a comment
Know the answer?
Add Answer to:
Using C++ And #include <stdio.h> #include <stdlib.h> #include <time.h> a) Write a main function and declare...
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
  • Complete the program below in C please #include <stdio.h> #inlcude <stdlib.h> #include <time.h> typedef struct {...

    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,...

    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...

    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...

    #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...

  • Write a Main function and a Function to compute and print the sine and cosine values...

    Write a Main function and a Function to compute and print the sine and cosine values of the array A elements which are angles in degrees. Within the MAIN function: • Declare a float array A to hold 50 angles in degrees. • Initialize array A elements from the standard input. • Pass the array A to the function as an argument. Within the function: • Read array A elements and compute and print the sine and cosine values of...

  • *Answer must be in C* Write a complete program as follows (declare any necessary variables): Create...

    *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 functi...

    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,...

  • C Programming #include <stdio.h> #include <stdlib.h> #include <time.h> // These defines do a text repl...

    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 the C programming language to complete #include <stdio.h> #include <stdlib.h> #include <float.h> // Declare Global...

    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...

  • Use C: 3. In function main, declare a two-dimensional integer array with 5 rows and 4...

    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...

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