0
818

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[0]=1, m[1]=2 Â after swapping we get m[0]=2 and m[1]=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[20], 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 */

SHARE
Previous articleInsert &Delete an element in 1-D array: C Program
I am third year student of computer engineering in L.D COLLEGE OF ENGINEERING,Ahmedabad.