Practical - 2 - Write a program to swap the value of two variables using third variable.

Practical - 2


Aim: Write a program to swap the value of two variables using third variable.

 

Program:

#include<stdio.h>

#include<conio.h>

 

void main()

{

    clrscr();

    int a, b, c;

   

    printf("Enter the value of 'A' = ");

    scanf("%d", &a);

   

    printf("Enter the value of 'B' = ");

    scanf("%d", &b);

   

    c = a;

    a = b;

    b = c;

 

    printf("\nA = %d", a);

    printf("\nB = %d", b);

   

    getch();   

}

 

 

Output:

 

Enter the value of 'A' = 4

Enter the value of 'B' = 5

 

A = 5

B = 4

 

 

Algorithm:

 

Step-1: START

Step-2: Declare a, b, c.

Step-3: Enter the value of a and b.

Step-4: c = a.

Step-5: a = b.

Step-6: b = c.

Step-7: Display a and b.

Step-8: STOP.

 

Flowchart:




 

Post a Comment

0 Comments
* Please Don't Spam Here. All the Comments are Reviewed by Admin.