C program to replace all EVEN elements by 0 and Odd by 1 in One Dimensional Array.
This program will read 10 elements of integer type using One Dimensional Array and replace all EVEN elements by 0 and ODD by 1.
To replace EVEN and ODD elements by 0 and 1, we will check each elements whether it is EVEN or ODD, if it is EVEN assign 0 otherwise assign 1 to the variable with index. For example arr[i] is EVEN, then we will assign arr[i]=0;
Replace EVEN and ODD elements by 0 and 1 using C program
Output
Enter elements : Enter arr[0] : 1 Enter arr[1] : 2 Enter arr[2] : 3 Enter arr[3] : 4 Enter arr[4] : 4 Enter arr[5] : 3 Enter arr[6] : 4 Enter arr[7] : 5 Enter arr[8] : 6 Enter arr[9] : 7 Before replacement : Elements are : arr[0] : 1 arr[1] : 2 arr[2] : 3 arr[3] : 4 arr[4] : 4 arr[5] : 3 arr[6] : 4 arr[7] : 5 arr[8] : 6 arr[9] : 7 After replacement : Elements are : arr[0] : 1 arr[1] : 0 arr[2] : 1 arr[3] : 0 arr[4] : 0 arr[5] : 1 arr[6] : 0 arr[7] : 1 arr[8] : 0 arr[9] : 1need an explanation for this answer? contact us directly to get an explanation for this answer