Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please covert this C program to C++ Thanks #include int main() { int NUM = 0; int* base; int* odd; int* even; int i= 0;

Please covert this C program to C++

Thanks

#include

int main() {

int NUM = 0; int* base; int* odd; int* even; int i= 0; int j= 0; int k=0;

printf("Enter the size of an array: "); scanf("%d", &NUM); base = (int*)malloc(NUM * sizeof(int)); odd = (int*)malloc(NUM * sizeof(int)); even = (int*)malloc(NUM * sizeof(int));

printf("Enter the elements (integers) of the array: "); for (i = 0; i < NUM; ++i) { scanf("%d", &(base[i])); }

for (i = 0; i < NUM; i++) { if (base[i] % 2 == 0){ even[j] = base[i]; j++; } else{ odd[k] = base[i]; k++; } } printf("The elements of the odd array are: "); for (i = 0; i < k; i++){ printf("%d ", odd[i]); } printf("The elements of the even array are: "); for (i = 0; i < j; i++){ printf("%d ", even[i]); } return 0; }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Administrator Limited Edition

Authors: Martif Way

1st Edition

B0CGG89N8Z

More Books

Students also viewed these Databases questions

Question

What are the two primary ways companies raise common equity?

Answered: 1 week ago

Question

=+and non-compete agreements in three to five different countries.

Answered: 1 week ago