0
781

# swap even odd number

### C program to swap even position numbers with odd position numbers and vice-versa

This C program swap or vice-versa even and odd numbers.For example consider i.e. m=1, m=2  after swapping we get m=2 and m=1. [message_box title=”PROGRAM” color=”yellow”]

/* Written by Utpal Chaudhary  */

/* Student of L.D COLLEGE OF ENGINEERING, Ahmedabad-15, Gujarat */

#include <stdio.h>
#include <conio.h>

void main()

{

int m, i, n, temp, limit;

clrscr();

printf (” How many elements ? \n”);

scanf (“%d”, n );

printf (” Enter % d  elements below \n”,n);

for(i=0; i<n; ++i )

{

scanf ( “%d”, &m[i] );

}

if ( n%2==0 )

{

limit =n;

}

else

{

limit =n-1;

}

for( i=0; i<limit; i+=2 )

{

temp=m[i];

m[i]=m[i+1];

m[i+1]=temp;

}

printf ( “After Swapping \n” );

for( i=0; i<n; ++i )

{

printf( ” %d \n  “, m[i] );

}

}

[/message_box]

/* Written by Utpal Chaudhary  */

/* Student of L.D COLLEGE OF ENGINEERING, Ahmedabad-15, Gujarat */

/* Written by Utpal Chaudhary  */

/* Student of L.D COLLEGE OF ENGINEERING, Ahmedabad-15, Gujarat */

/* Written by Utpal Chaudhary  */

/* Student of L.D COLLEGE OF ENGINEERING, Ahmedabad-15, Gujarat */

/* Written by Utpal Chaudhary  */

/* Student of L.D COLLEGE OF ENGINEERING, Ahmedabad-15, Gujarat */

/* Written by Utpal Chaudhary  */

/* Student of L.D COLLEGE OF ENGINEERING, Ahmedabad-15, Gujarat */

/* Written by Utpal Chaudhary  */

/* Student of L.D COLLEGE OF ENGINEERING, Ahmedabad-15, Gujarat */

/* Written by Utpal Chaudhary  */

/* Student of L.D COLLEGE OF ENGINEERING, Ahmedabad-15, Gujarat */

/* Written by Utpal Chaudhary  */

/* Student of L.D COLLEGE OF ENGINEERING, Ahmedabad-15, Gujarat */

/* Written by Utpal Chaudhary  */

/* Student of L.D COLLEGE OF ENGINEERING, Ahmedabad-15, Gujarat */

/* Written by Utpal Chaudhary  */

/* Student of L.D COLLEGE OF ENGINEERING, Ahmedabad-15, Gujarat */