in a given array a[1,2,3,4], b[5,6,2,8] if the element present at each position in both array is even even or odd odd then multiply both numbers else take first array element as it is and store it in another array. expected output C[5,12,3,32] in C language
Answers
Answered by
3
Answer:
#include <stdio.h>
int main()
{
int a[] = {1,2,3,4};
int b[] = {5,6,2,8};
int c[] = {};
int len = sizeof(a)/sizeof(a[0]);
for(int i = 0; i < len; i++){
if(a[i] % 2 == 0 && b[i] % 2 == 0){
c[i] = a[i]*b[i];
}
else if(a[i] % 2 == 1 && b[i] % 2 == 1){
c[i] = a[i]*b[i];
}
else{
c[i] = a[i];
}
}
for(int i = 0; i < len; i++){
printf("%d " , c[i]);
}
return 0;
}
Explanation:
See the output is correct-
Please mark as brainliest
Attachments:
Similar questions