Question

Write a program that generates 20 random integers (ranging in between 0 to 100) and outputs all the even random numbers.

C language

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

Answer:

Explanation:

srand function is used to put a seed for random generation so that on every program run, different numbers are generated.

rand() function is used inside a for loop which runs 20 times from i=0 to i=19 and if the number generated is even, only then it is printed, otherwise not.

feel free to comment if you have any doubts!

COde

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main()
{
srand(time(0));
  
for(int i=0; i<20; i++)
{
int n = rand()%101;
  
if(n%2==0)
printf("%d ", n);
}

return 0;
}

Output:

28 14 66 4 14 54 18 38 ...Program finished with exit code 0 Press ENTER to exit console.

PLEASE UPVOTE IF YOU FOUND THIS HELPFUL!

PLEASE COMMENT IF YOU NEED ANY HELP!

Add a comment
Know the answer?
Add Answer to:
C language Write a program that generates 20 random integers (ranging in between 0 to 100)...
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
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