Write a C++ program that will ask user to enter two integral numbers. The numbers should be swapped without using any third variable.

C++ program that will ask user to enter two integral numbers. The numbers should be swapped without using any third variable.

Write a C++ program that will ask user to enter two integral numbers. The numbers should be swapped without using any third variable.

 

Object:

Write a C++ program that will ask user to enter two integral numbers. The numbers should be swapped without using any third variable. Your code should be able to do the same process for 30 cycles. It should also show the swapped numbers at the each cycle. C++ Projects.

Code:

#include<iostream>
#include<conio.h>

using namespace std;
void main()
{
int a,b;
for(int i=1; i<=30; i++)
{
cout<<“\nCycle:”<<i<<endl;
cout<<“\nPlease Enter Any Numbers.\n”;
cout<<“Enter a Value a : “;
cin>>a;
cout<<“Enter a Value b : “;
cin>>b;
a=a+b;
b=a-b;
a=a-b;
cout<<“\nAfter Swapping These Two Numbers.\n”;
cout<<“Vale of a is: “<<a<<endl;
cout<<“Vale of b is: “<<b<<endl;
}
getch();
}

Output:

Write a C++ program that will ask user to enter two integral numbers. The numbers should be swapped without using any third variable.

Another Program: Write a C++ program which takes the price of bakery items ranging from 0-999

M.A Siddiqui

Hi, I am M.A Siddiqui. I'm a Computer Science Student, In this website, I'm teaching you Multiple languages and provides Projects and other Subjects Notes.

You may also like...

2 Responses

  1. June 4, 2020

    […] Another Program: Write a C++ program that will ask user to enter two integral numbers. The numbers s… […]

  2. June 14, 2020

    […] Write a C++ program that will ask user to enter two integral numbers. The numbers should be swapped … […]

Leave a Reply

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