Computer Science, asked by santhoshy8013, 1 year ago

Write an algorithm and flow chart to swap two numbers without using third variable

Answers

Answered by homosapiens45
202

Algorithm with out using a third variable


Step 1: Start

Step 2: Read the value of Number1,Number2

Step 3: Number1= Number1 + Number2

Step 4: Number2= Number1 - Number2

Step 5: Number1= Number1 - Number2

Step 6: PRINT the value of Number1 and Number2

Step 7: Stop


Flowchart Attached below.

Attachments:
Answered by bharathparasad577
0

Answer:

Explanation:

Swapping :

Swapping is the process of altering the values of two variables interchangeably.

Algorithm:

An algorithm is a process used to carry out a computation or solve a problem. Algorithms function as a precise list of instructions that carry out defined activities in a step-by-step fashion.

Algorithm for swapping without third variable:

Step 1 : Declare two variables a and b

Step 2 : Get the values for the declared variables from the user

Step 3: Print the values entered by user.

Step 4 :Perform addition and subtraction to perform swapping of values as follows:

Step 4.1 : a=a+b

Step 4.2 : b=a-b

Step 4.3 :a=a-b

Step 5 : Print the swapped values of a and b

#SPJ3

Attachments:
Similar questions