Monday, 19 September 2016

DS-LAB(SWAPPING TWO NO.S)EXPERIMENT-10

ALGORITHM

START

   Var1, Var2, Temp
   
   Step 1 → Copy value of Var1 to Temp
   
   Step 2 → Copy value of Var2 to Var1
          
   Step 3 → Copy value of Temp to Var2

STOP
FLOWCHART:
Image result for FLOWCHART of swapping two numbers
PROGRAM:
#include <iostream>
using namespace std;

int main() {
    
    int a = 5, b = 10, temp;
    cout << "Before swapping." << endl;
    cout << "a = " << a << ", b = " << b << endl;

    temp = a;
    a = b;
    b = temp;

    cout << "\nAfter swapping." << endl;
    cout << "a = " << a << ", b = " << b << endl;


    return 0;
}

No comments:

Post a Comment