Header Ad

C Program to swap two numbers using a function

In this tutorial, we are going to write a C Program to swap two numbers using a function in C Programming with practical program code and step-by-step full complete explanation.

C Program to swap two numbers using a function


C Program to swap two numbers using a function

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

void main()
{
	void swap(int,int);

	int a,b,r;
	clrscr();

	printf("Enter value for a&b: ");
	scanf("%d%d",&a,&b);
	swap(a,b);

	getch();
}

void swap(int a, int b)
{
	int temp;
	temp = a;
	a=b;
	b=temp;
	printf("After swapping the value for a & b is: %d %d",a,b);
}


Output

 
Enter value for a&b: 4
5
After swapping the value for a & b is: 5 4


Post a Comment

0 Comments