Question

Part II. Write a programming segment that generates 25 random integers between 0 and 99. Place the even numbers in an array called EVEN and then place the odd numbers in an array called ODD. Print the EVEN array and Print the ODD array
0 0
Add a comment Improve this question Transcribed image text
Answer #1

code in c++:

#include<iostream>

#include<cstdlib>

using namespace std;

bool inEven(int, int[], int);

bool inOdd(int, int[], int);

int main(){

int even[25] = {0};

int odd[25] = {0};

int n = 25;

int e = 0, o = 0;

while(n>0){

int temp = rand() % 100;

if(temp % 2 == 0){

if(!inEven(temp, even, e)){

even[e++] = temp;

--n;

}

}

else{

if(!inOdd(temp, odd, o)){

odd[o++] = temp;

--n;

}

}

}

for(int i=0; i<e; i++){

cout<<"even: "<<even[i]<<endl;

}

for(int i=0; i<o; i++){

cout<<"odd: "<<odd[i]<<endl;

}

return 0;

}

bool inEven(int temp, int arr[], int e){

for(int i=0; i<e; i++){

if(arr[i] == temp)

return true;

}

return false;

}

bool inOdd(int temp, int arr[], int o){

for(int i=0; i<o; i++){

if(arr[i] == temp)

return true;

}

return false;

}

Wed May 9, 01:15 Activities Visual Studio Code ▼ random.cpp coding-Visual Studio Code File Edit Selection View Go Debug Tasks

Wed May 9, 01:16 Activities Visual Studio Code random.cpp coding-Visual Studio Code File Edit Selection View Go Debug Tasks H

Activities Terminal ▼ Wed May 9, 01:16 40 100% random.cpp-coding- Visual Studio Code File Edit Selection View Go Debug Tasks

a choose c++, you don't may require another language but the concept is same. if you want this question in other language do comment. I am happy to help you thanks.

Add a comment
Know the answer?
Add Answer to:
Part II. Write a programming segment that generates 25 random integers between 0 and 99. Place...
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