forked from MAYANK25402/Hacktober-Fest-2022
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a0db9c6
commit cecce85
Showing
1 changed file
with
59 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* C Program to replace all Even elements by 0 and Odd by 1 */ | ||
|
||
#include <stdio.h> | ||
|
||
void readArray(int arr[], int size) | ||
{ | ||
int i =0; | ||
|
||
printf("Enter elements of array :: \n"); | ||
|
||
for(i=0; i < size; i++) | ||
{ | ||
printf("\nEnter arr[%d] :: ",i); | ||
scanf("%d",&arr[i]); | ||
} | ||
} | ||
|
||
void printArray(int arr[], int size) | ||
{ | ||
int i =0; | ||
|
||
printf("\nElements are : "); | ||
|
||
for(i=0; i < size; i++) | ||
{ | ||
printf("\narr[%d] : %d",i,arr[i]); | ||
} | ||
printf("\n"); | ||
} | ||
|
||
void replaceEvenOdd(int arr[], int size) | ||
{ | ||
int i=0; | ||
|
||
for(i=0; i < size; i++) | ||
{ | ||
if( arr[i] % 2 == 0 ) | ||
arr[i] = 0 ; | ||
else | ||
arr[i] = 1 ; | ||
} | ||
} | ||
|
||
int main() | ||
{ | ||
int arr[10]; | ||
|
||
readArray(arr,10); | ||
|
||
printf("\nBefore replacement : "); | ||
printArray(arr,10); | ||
|
||
replaceEvenOdd(arr,10); | ||
|
||
printf("\nAfter replacement : "); | ||
printArray(arr,10); | ||
|
||
return 0; | ||
} |