Advertisement
stsharin

Untitled

Dec 9th, 2018
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. //find the max even and max odd number and then swap them and print
  2. #include<stdio.h>
  3. int main()
  4. {
  5. int a[1000],size,emax,omax,emaxi,omaxi,temp=0;
  6. printf("Enter array size: ");
  7. scanf("%d",&size);
  8.  
  9. int i;
  10. for(i=0;i<size;i++){
  11. scanf("%d",&a[i]);
  12. }
  13. emax=a[0]; omax=a[0];
  14. for(i=0;i<size;i++){
  15. if(a[i]%2==0){
  16. if(a[i]>emax){
  17. emax=a[i];
  18. emaxi=i;
  19. }
  20. }
  21. else{
  22. if(a[i]>omax){
  23. omax=a[i];
  24. omaxi=i;
  25. }
  26. }
  27. }
  28. temp= a[emaxi];
  29. a[emaxi]=a[omaxi];
  30. a[omaxi]=temp;
  31.  
  32. for(i=0;i<size;i++){
  33. printf("%d ",a[i]);
  34. }
  35.  
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement