C program for swap function

Posted: January 19, 2012 in Lab 2

Problem Statement- Complete the following program by defining the function swapb() and its prototype such that the output of the program is 20 10.
#include
void swapa(int&, int&);
void main()
{
int a=10, b=20;
swapa(a,b);
cout<<a<<b;
}

void swapa(int& x, int& y)
{
swapb(x,y);
}

#include <stdio.h>
void swapa(int *, int *);
int swapb(int *, int *);
void main()
{
   int a=10, b=20;
   swapa(&a,&b);
   printf("%d %d",a,b);
}

void swapa(int *x, int *y)
{
   swapb(&*x,&*y);
}
int swapb(int *x, int *y)
{
	int t;
	t=*y;
	*y=*x;
	*x=t;
	return(*x,*y);
}
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