Question
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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started