Monday, 14 December 2020

Write a Program in C++ to interchange the value of 2 variables without using third variable.

#include <iostream>

using namespace std;

main()

{

  int a,b;

  cout<<"Enter 2 Numbers"<<endl; 

  cin>>a>>b;

  cout<<"Before Swapping :\nThe first Number = "<<a<<endl;;

  cout<<"The Second Number = "<<b<<endl;

  a=a+b;

  b=a-b;

  a=a-b;

  cout<<"After Swapping :"<<endl;

  cout<<"The first Number = "<<a<<endl;

  cout<<"The second Number = "<<b<<endl;

}

No comments:

Post a Comment

Java Program to count the total number of characters in a string

 //Java Program to count the total number of characters in a string import java.util.*; public class CountChars {     public static void mai...