can you assist in this c program Problem 1 Write a program t
can you assist in this c++ program.
Problem 1:
Write a program that will read two floating point numbers (the first read into a variable
called first and the second read into a variable called second). Your main function should
print out the values of these two numbers immediately after they are read. Your main function
should then call a function named swap with the actual parameters first and second. The
swap function having formal parameters number1 and number2 should swap the value of
the two variables. Your main function should print the values of first and second again after
the swap function returns.
Sample Run:
Enter the first number
Then hit enter
80
Enter the second number
Then hit enter
70
You input the numbers as 80 (first) and 70 (second).
After swapping, the first number has the value of 70
and the second number has the value of 80.
Solution
#include <iostream>
void swap(double *p1,double *p2)
{
*p1=*p1+*p2;
*p2=*p1-*p2;
*p1=*p1-*p2;
}
int main()
{
double first,second;
std::cout<<\"Enter The First Floating ponit number\"<<std::endl;
std::cin>>first;
std::cout<<\"Enter The Second Floating ponit number\"<<std::endl;
std::cin>>second;
std::cout<<\"You input the numbers as first= \\t\"<<first<<\"\\t and second=\\t\"<<second<<std::endl;
swap(&first, &second);
std::cout<<\"Numbers are After Swaping first = \\t\"<<first<<\"\\t and second=\\t\"<<second<<\"\ \";
return 0;
}
