Write a C program to create the double arrays A and B, using the gen rand mat function.

C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter7: Arrays
Section7.3: Declaring And Processing Two-dimensional Arrays
Problem 4E: (Practice) Write a C++ program that adds equivalent elements of the two-dimensional arrays named...
icon
Related questions
Question
100%

Write a C program to create the double arrays A and B, using the gen rand mat function.

Expert Solution
Step 1

Program Approach:

  • Including a necessary header file
  • Declaring a method to generate a random floating-point number from min to max
  • Declaring the main method
  • Declaring two arrays A and B
  • Declaring integer variable i
  • Using for loop to store value in the array
  • Display the message
  • Using for loop to generating a random value
  • Display the value
Step 2

Program:

//including necessary header file

#include <stdio.h>

#include <stdlib.h>

//declaring a method to generate a random floating point number from min to max

double gen_rand_num(double min, double max)

{

double range = (max - min);

double num = RAND_MAX / range;

return min + (rand() / num);

}

//declaring main method

int main(){

//declaring two array A and B

double A[10],B[10];

//declaring integer variable i

int i;

//using for loop to store value in array

for(i=0;i<10;i++){

A[i] = gen_rand_num(1,100);

B[i] = gen_rand_num(1,100);

}

//display the message

printf("Random generated double array 1:\n");

//using for loop to generating random value

for(i=0;i<10;i++)

//display the values

printf("%f ",A[i]);

//display the message

printf("\nRandom generated double array 2:\n");

//using for loop to generating random value

for(i=0;i<10;i++)

//display the value

printf("%f ",B[i]);

//return the value

return 0;

}

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Randomized Select Algorithm
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr