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();
}

#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

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

  1. Pingback: Write a program that asks the user to enter a number of seconds.

  2. Pingback: C++ projects for beginners with source code - Codeboks

  3. Pingback: C++ Program one large chemical company pays its salespeople on a commission basis

Leave a Comment

Your email address will not be published.