Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program that will read two floating point numbers (the first read into a

ID: 667695 • Letter: W

Question

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) and then calls the function 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.

Sample Run:

Enter the first number

Then hit enter

80

Enter the second number

Then hit enter

70

You input the numbers as 80 and 70.

After swapping, the first number has the value of 70 which was the value of the

second number

The second number has the value of 80 which was the value of the first number

Explanation / Answer

include <stdio.h>
int main()
{
float a, b, temp;
printf("Enter value of a: ");
scanf("%f",&a);
printf("Enter value of b: ");
scanf("%f",&b);
temp = a;    //* Value of a is stored in variable temp *//
a = b;         //* Value of b is stored in variable a *//
b = temp;    //* Value of temp(which contains initial value of a) is stored in variable b*//
printf(" After swapping, value of a = %.2f ", a);
printf("After swapping, value of b = %.2f", b);
return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote