Computer Science, asked by tsg0, 7 months ago

Specify a class Demo to initialize two integers ' m'& 'n' with the values 4 and 18 . Interchange the values of ' m ' & 'n' without using any other variable apart from and n ​

Answers

Answered by dusaudayasri
3

Answer:

Given two variables, x and y, swap two variables without using a third variable.

Method 1 (Using Arithmetic Operators)

The idea is to get sum in one of the two given numbers. The numbers can then be swapped using the sum and subtraction from sum.

// C++ Program to swap two numbers without

// using temporary variable

#include <bits/stdc++.h>

using namespace std;

int main()

{

int x = 10, y = 5;

// Code to swap 'x' and 'y'

x = x + y; // x now becomes 15

y = x - y; // y becomes 10

x = x - y; // x becomes 5

cout << "After Swapping: x =" << x << ", y=" << y;

}

// This code is contributed

Answered by MysticalRainbow
2

Answer:

haha honey sir sahi kha vo shi dp lagai hai uske liye dimag kharab ho jayega uska test karne mey

Similar questions