-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathswapDigits.cpp
More file actions
41 lines (35 loc) · 829 Bytes
/
swapDigits.cpp
File metadata and controls
41 lines (35 loc) · 829 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
//c++ program to swap two numbers by using third variable
/*#include<iostream>
using namespace std;
int main()
{
int n1, n2, temp;
cout<<"enter first number: "<<endl;
cin>>n1;
cout<<"enter second number: "<<endl;
cin>>n2;
cout<<"Numbers before swapping: "<<n1<<" "<<n2<<endl;
temp=n1;
n1=n2;
n2=temp;
cout<<"Numbers after swapping: "<<n1<<" "<<n2<<endl;
return 0;
}
*/
//c++ program to swap two digits without using third variable
#include<iostream>
using namespace std;
int main()
{
int n1, n2;
cout<<"enter first number: "<<endl;
cin>>n1;
cout<<"enter second number: "<<endl;
cin>>n2;
cout<<"Numbers before swapping: "<<n1<<" "<<n2<<endl;
n1=n1*n2;
n2=n1/10;
n1=n1/n2;
cout<<"Numbers after swapping: "<<n1<<" "<<n2<<endl;
return 0;
}