Question: PROBLEM 2: Swap two numbers (Use C language to solve it) Design a program to swap two numbers. Include code to perform this using two

PROBLEM 2: Swap two numbers (Use C language to solve it)

Design a program to swap two numbers. Include code to perform this using two approaches.

  1. Using a temporary variable.
  2. Direct swap between the two variables.

TIP: Use scanf and printf functions. Also use float/double data type for all variables.

Example input: (Text in purple is what the program should print on the screen to instruct the user, text in black is what the user types in)

Enter x and y: 1.3 9.5

Example output:

Before swapping: x=1.3, y=9.5

After swapping using a temporary variable: x=9.5, y=1.3 After direct swapping the variables: x=9.5, y=1.3

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!