Math, asked by safruddeensaifi284, 1 year ago

Algorithm and flowchart for swapping of two numbers using third variable

Answers

Answered by Nitinsingh192
9

1:start.

2:read a,b,temp.

3.temp=a;

a=b;

b=temp;

4:print a,b.

5:stop

for flow chart use

oval shape for stop and start

rectangle for 3rd step

parrelogram for print and read

all should joined by arrows

OR

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

Answered by ishwaryam062001
0

Answer:

Swapping means interchanging. Swapping two numbers using a third variable.

Step-by-step explanation:

From the above question,

They have given :

1. Begin

2. Declare three variables A, B, and temp

3. Assign the values to A and B

4. Store the value of A in temp

5. Assign the value of B to A

6. Assign the value of temp to B

7. Print the values of A and B

8. End

Swapping means interchanging. Swapping two numbers using a third variable.

Step 1: Take the value of first number in a temporary variable say temp.

Step 2: Assign the value of second number to first number.

Step 3: Assign the value of temp to second number.

Hence the two numbers are swapped.

Program :

#include<stdio.h>

int main()

{

int a,b,temp;

printf("enter two numbers\n");

scanf("%d%d",&a,&b);

printf("before swapping a=%d and b=%d\n",a,b);

temp=a;

a=b;

b=temp;

printf("after swapping a=%d and b=%d\n",a,b);

return 0;

}

For more such related questions : https://brainly.in/question/48797514

#SPJ3

Attachments:
Similar questions