Answer to Question #210902 in C for genji 5

Question #210902

Write a program to swap two numbers using temporary variables and functions (call by value


1
Expert's answer
2021-06-29T05:52:46-0400
#include <stdio.h>


int a, b;
void Swap(int x, int y)
{
	int temp;
	temp = x;
	b = x;
	a = temp;
}
main(void)
{
	int temp;
	a=20;	b=30;
	printf("\nSwapping Method Using temp:\tBefore Swapping: a = %d,\tb=%d",a,b);
	temp=a;
	a = b;
	b = temp;
	printf("\n\t\t\t\tAfter Swaping  : a = %d,\tb=%d",a,b);
	a=20;	b=30;
	printf("\n\n\nSwapping Method Using Swap Function by Value:");
	printf("\n\tBefore Swapping: a = %d,\tb=%d",a,b);
	swap(a,b);
	printf("\n\ttfter Swaping  : a = %d,\tb=%d",a,b);
	return(0);
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS