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

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
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.
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education