C Program to swap two numbers using + and - without third variable
// C Program to swap two numbers using + and - without third variable
#include<stdio.h> //header file declaration
int main() //main method
{
int p=25, q=50; //variable declaration
printf("Before swapping values: p=%d q=%d\n",p,q); //Before swapping value
p=p+q;
q=p-q; //use of + and -
p=p-q;
printf("\nAfter swapping values: p=%d q=%d",p,q); // After swapping value
return 0;
}
OUTPUT:
Comments
Post a Comment