Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //find the max even and max odd number and then swap them and print
- #include<stdio.h>
- int main()
- {
- int a[1000],size,emax,omax,emaxi,omaxi,temp=0;
- printf("Enter array size: ");
- scanf("%d",&size);
- int i;
- for(i=0;i<size;i++){
- scanf("%d",&a[i]);
- }
- emax=a[0]; omax=a[0];
- for(i=0;i<size;i++){
- if(a[i]%2==0){
- if(a[i]>emax){
- emax=a[i];
- emaxi=i;
- }
- }
- else{
- if(a[i]>omax){
- omax=a[i];
- omaxi=i;
- }
- }
- }
- temp= a[emaxi];
- a[emaxi]=a[omaxi];
- a[omaxi]=temp;
- for(i=0;i<size;i++){
- printf("%d ",a[i]);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement