Interchange Values of Variables coderinme

Interchange Values of Variables coderinme

Interchange Values of Variables coderinme
In a computer programming, the act of swapping two variables refers to mutually exchanging the values of the variables. Since swap means to exchange, Therefore in C swapping of variables simply means exchanging the value of one variable with another variable.
So, In order to interchange the value of two variables or to swap two variables we code as following

#include<stdio.h>
int main()
{
int a,b;
printf("Please input the value of a: ");
scanf("%d",&a);
printf("Please input the value of b: ");
scanf("%d",&b);
printf("The input value of a is %d and b is %d\n",a,b);
a = a + b;
b = a - b;
a = a - b;
printf("The swapped value of a is %d and value of b is %d",a,b);
getch();
return 0;
}

For more programs in C, visit our C Coder Archives

Interchange Values of Variables coderinme

All rights reserved. No part of this Post may be copied, distributed, or transmitted in any form or by any means, without the prior written permission of the website admin, except in the case of brief quotations embodied in critical reviews and certain other noncommercial uses permitted by copyright law. For permission requests, write to the owner, addressed “Attention: Permissions Coordinator,” to the admin @coderinme

Leave a reply:

Your email address will not be published.