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