C++ program to swap two numbers without using temp variable

#include<iostream.h>
#include<conio.h>void main()
{
clrscr();
int a,b;
cout<<“Enter value of a:”;
cin>>a;
cout<<“Enter value of b:”;
cin>>b;

a=a+b;
b=a-b;
a=a-b;

cout<<“na=”<<a;
cout<<“nb=”<<b;
getch();
}

One thought on “C++ program to swap two numbers without using temp variable

  1. keegan

    how can i solve the following,
    USING C++, Write a menu driven application for a game that your pupils can use to improve their arithmetic skills. Once started, the game should allow the player to choose one option from the four presented options namely: 1. Perform a Modulus division of two numbers
    2. Perform Multiplication of two numbers
    3. Perform Subtraction of two numbers
    4. Exit

    Upon selection of the operation they wish to undertake, the program should then allow the user to provide the required numbers for the operation. Once values are provided, the program should ask the user what the response is when the desired operation is carried out on the two number. A user should be given two chances only to try and guess the right response, if they exhaust the two chances they should be provided with the right answer. If they guess the result correctly, they should be recommended with a message of congratulation. After this is done, the user should be presented with the menu requesting them to choose another operation to carry out or exit the program

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.