Showing posts with label Swapping of two numbers. Show all posts
Showing posts with label Swapping of two numbers. Show all posts

Tuesday, May 28, 2019

C Programming : Program to swap two numbers

/* Program to swap two numbers */

#include<stdio.h>
#include<conio.h>
void main( )
{
float A,B;
printf("\n Enter the value of A  ");
scanf("%f ",&A);
printf("\n Enter the value of B  ");
scanf("%f ",&B);
printf("\n  Numbers before swapping are :- \n A=%f\nB=%f",A,B); 
A=A+B;
B=A-B;
A=A-B;
printf("\n Numbers after swapping are :-");
printf("\n A=%f \nB=%f",A,B);
getch();
}

Output

Enter the value of
30.0

Enter the value of B
90.0
Numbers before swapping are :-
A=30.000000
B=90.000000
Numbers after swapping are:-
A=90.000000
B=30.000000
 
Now the demonstration of the output is shown below:


Function

FUNCTION C enables programmer to break up a program into segments commonly known as functions, each of which can be written more or...