Question

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

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

0 0
Add a comment Improve this question Transcribed image text
Answer #1

C Program:

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

// 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);
}

int main(){
double A[10],B[10];
int i;
for(i=0;i<10;i++){
A[i] = gen_rand_num(1,100);
B[i] = gen_rand_num(1,100);
}
printf("Random generated double array 1:\n");
for(i=0;i<10;i++)
printf("%f ",A[i]);
printf("\nRandom generated double array 2:\n");
for(i=0;i<10;i++)
printf("%f ",B[i]);
return 0;
}

Output:

Add a comment
Know the answer?
Add Answer to:
Write a C program to create the double arrays A and B, using the gen rand...
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
  • Write a C program that uses the random number generator rand( ) to create an array...

    Write a C program that uses the random number generator rand( ) to create an array with 20 numbers with value in the range from 1 to 100. The program calculates and displays the difference between the largest array element and the second largest array element in the array.

  • Create a C++ language program which feeds randomly generated number using the rand function into a...

    Create a C++ language program which feeds randomly generated number using the rand function into a multidimensional array. Create this array such that it has 5 columns and 5 rows of randomly generated values . Then display the contents of the array, and in addition display the sum of each row and the sum of each column in the array.

  • 2. Write a C program that using arrays A and B calculates the given formula. The...

    2. Write a C program that using arrays A and B calculates the given formula. The program should save the results in the Carray and then print it. int A[7] = {215, 431, 25, 64, 18, 99, 105); int B[7] = {50, 78, 31, 477, 22, 258, 312); (100 Points) C[i] (A[i]+B[i])x2 median (A)+median(B) Enter your answer 2. Write a program that using arrays A and calculates the given tornog Save the results in the Carray and then print int...

  • For c++ Write a complete C++ program and declare 2 arrays type double size 5. The...

    For c++ Write a complete C++ program and declare 2 arrays type double size 5. The name of the first array is Salary and the name of the second array is Tax. Use a for loop loop and enter 5 salaries type double into array Salary. Then multiply each element of array Salary by .10 (10 percent), and save the result into array Tax. Print/display the content of both arrays. Hint: the content of array Tax is 10% percent of...

  • Using C++ Write a function that given two dynamical arrays (A and B) of doubles of...

    Using C++ Write a function that given two dynamical arrays (A and B) of doubles of a given size N, will return a N by N dynamical array C such that C[i][j]=A[i]*B[j]. e.g. A={1,2,3}, B={10,20,30}, will result in C={{10,20,30},{20,40,60}, {30, 60, 90}} double** outerProd(double *A, double *B, int size);

  • Write a program that calculates voltage from current and resistance values. Create three one-dimensional arrays named...

    Write a program that calculates voltage from current and resistance values. Create three one-dimensional arrays named current, resistance and voltage, each capable of holding 10 double-precision values. The values stored in current and resistance are as follows: current = 10.62, 14.89, 13.21, 16.55, 18.62, 9.47, 6.58, 18.32, 12.15, 3.98 resistance = 4.0, 8.5, 6.0, 7.35, 9.0, 15.3, 3.0, 5.4, 2.9, 4.8 Have your program pass these three arrays to a function called calcVolts() which calculates the elements in the voltage...

  • Q1. Write a program in Java         a. Create 2 separate arrays, of user defined values,...

    Q1. Write a program in Java         a. Create 2 separate arrays, of user defined values, of same size         b. Add these 2 arrays. ........................................................................................................................... Q2. Write a program in java (using loop) input any10 numbers from user and store in an array. Check whether each of array element is positive, negative, zero, odd or even number. ............................................................................................................................ Q3. Write a program in Java to display first 10 natural numbers. Find the sum of only odd numbers. .............................................................................................................................. Q4....

  • Language C Code Write a program that takes two integer arrays (A and B) and sums...

    Language C Code Write a program that takes two integer arrays (A and B) and sums them together (element wise). A third array to accept the result should be passed in as the output argument. Assume the arrays are all the same size. The argument N is the size of the arrays. Your code should provide a function with the following signature: void array Addition (int A[], int B[], int N, int output[]) { } Your code must also provide...

  • Must use JOPTIONPANE. Using arrays and methods create a JAVA program. Create a java program that...

    Must use JOPTIONPANE. Using arrays and methods create a JAVA program. Create a java program that holds an array for the integer values 1-10. Pass the array to a method that will calculate the values to the power of 2 of each element in the array. Then return the list of calculated values back to the main method and print the values

  • Q 3-) (30 points) Write a C program (MAIN function) and a FUNCTION to create and...

    Q 3-) (30 points) Write a C program (MAIN function) and a FUNCTION to create and print the transpose of a two- dimensional array. Within C program (the MAIN function); Declare a two- dimensional 3X2 integer array A and initialise with the values (1,2), (3,4), (5,6), declare also a two-dimensional 2X3 integer array B and initialise it with zero. Call the FUNCTION and pass arrays A and B to the FUNCTION as arguments. Print the array A and its transpose....

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