Write a program to swap two numbers
Answers
Answered by
2
Answer:
Swap Numbers Using Temporary Variable
#include<stdio.h>
double first, second, temp;
printf("Enter first number: ");
scanf("%lf", &first);
printf("Enter second number: ");
scanf("%lf", &second);
// Value of first is assigned to temp.
temp = first;
mark as brilliant answer
Answered by
0
Answer:
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a, b;
//input
cout<<"\nEnter first number:";
cin>>a;
cout<<"\nEnter second number:";
cin>>b;
cout<<"\nNumbers before swap=";
cout<<a<<endl<<b;
//swap
a=a+b;
b=a-b;
a=a-b;
//output
cout<<"\nNumbers after swap=";
cout<<a<<endl<<b;
getch();
}
Similar questions