- #1
freezer
- 76
- 0
Homework Statement
A simple method to get a random uniform variable of data type float, between 0 (inclusive) and 1 (exclusive) is:
x = rand()/(RAND_MAX + 1);
where x is a float.
Write a program that fills an array with 1000 integers random numbers, then uses those to fill another array with 100 float random numbers between 0 and 1. Find and print out the average value of the integer array and float array.
Homework Equations
The Attempt at a Solution
I am confused about the second array and how i would use x variable and the first array to fill the second array.
Here what I have so far to fill the arrays:
Code:
#include<stdio.h>
#include<cstdlib>
#include<time.h>
#define SIZE1 1000
#define SIZE2 100
void main(void)
{
float x;
int bob[SIZE1];
float sam[SIZE2];
srand( (unsigned)time( NULL ) );
for(int i = 0; i < SIZE1; i++)
{
bob[i] = rand();
}//End For Loop 1
for(int i=0; i<SIZE2; i++)
{
x = rand()/(RAND_MAX + 1.0);
sam[i] = x;
}// End for loop 2
}//End Main