• C

randomized

can you write me a program how to show the sum of 100 randomized number which 1) between 1000 and 5000
                        2) between 5001 and 9999
samuelccsAsked:
Who is Participating?
 
hougaardConnect With a Mentor Commented:
void main()
{
  int i;
  double r;
  double rsum1 = 0;
  double rsum2 = 0;

  for (i = 0;i <= 100; i++)
  {
    rsum1 += (4000.0 * (rand() / 32767.0)) + 1000.0 ;
    rsum2 += (4998.0 * (rand() / 32767.0)) + 5001.0 ;
  }
}

0
 
samuelccsAuthor Commented:
can you show me some example of  "randomized program" ?
0
 
samuelccsAuthor Commented:
do you have any more example about randomized. can you show me some of those xample?
0
 
samuelccsAuthor Commented:
may i know why you divide random() with 32767. what is 32767
0
 
hougaardCommented:
rand() returns 0 - 32767 - so to get the fraction (0-1) i devide
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.