Program for writing macro for swap without using temporary variable

#include <stdio.h>
#define swap(x,y) x=x+y;y=x-y;x=x-y
#define TABLESIZ     10
int table[]={15,2,45,60,12,20,21,16,65,81};
int main()
{
int i,j;
for(i=0;i<TABLESIZ-1;i++)
for(j=i+1;j<TABLESIZ;j++)
if(table[i] > table[j])
{
swap(table[i],table[j]);
}
for(i=0;i<TABLESIZ;i++)
printf("%3d",table[i]);
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s