45.4k views
4 votes
Create procedures for the following:

1. Generates a random number between 5000d and 10000d
inclusive.
2. The number of numbers to be generated is up to the
user, but will not be more than 25d.
3. Determine the sum of the array.
numbers together.
declared above main.
That is add all the
Save the result in a variable
4. Print the array, 1 element per line as shown below
arrayName [0]
=
5. After printing the array, print the sum in hex,
decimal and binary.
The sum of arrayName is :
In Hexadecimal :
:
###
#
#
#
#
###
In Decimal
In Binary
:

User Nebuto
by
8.0k points

1 Answer

1 vote

Final answer:

To generate random numbers between 5000 and 10000 and determine their sum, you can follow these steps: create an array, prompt the user for the number of numbers to generate, use a loop to generate random numbers and store them in the array, calculate the sum of the array, and print the array and the sum in different formats.

Step-by-step explanation:

Procedure to Generate Random Numbers and Determine the Sum

  1. Create an array to store the randomly generated numbers.
  2. Prompt the user to enter the number of random numbers to be generated (up to 25).
  3. Use a loop to generate the specified number of random numbers between 5000 and 10000 (inclusive) and add them to the array.
  4. Calculate the sum of the numbers in the array.
  5. Print each element of the array on a new line.
  6. Print the sum in hexadecimal, decimal, and binary formats using appropriate conversion functions.

Example code:

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int main() {
int i, n;
int array[25];
int sum = 0;

srand(time(0));

printf("Enter the number of random numbers to be generated (up to 25): ");
scanf("%d", &n);

for(i = 0; i < n; i++) {
array[i] = rand() % 5001 + 5000;
sum += array[i];
}

printf("The array elements are:\\");
for(i = 0; i < n; i++) {
printf("array[%d] = %d\\", i, array[i]);
}

printf("\\The sum of the array is: %d\\", sum);
printf("In Hexadecimal: %x\\", sum);
printf("In Decimal: %d\\", sum);
printf("In Binary: %d\\", sum);

return 0;
}

User Amol Suryawanshi
by
8.5k points