HSC – SWAPPING IN C++ | eXP-1

Write a function in C that extends the data (passing by reference) using the swap function to interchange the given two numbers.

Hey there, it’s your friendly neighborhood computer engineer, Vinit Pandey! I’m the mastermind behind smmwizardpro.com and edu4maharashtra.in – websites so cool they’ll make your head spin. And if you’re not following me on Instagram at vinit.bro, well, let’s say I am missing you their.

So if you want to level up your tech game, just hit me up. I promise I won’t bite – unless you’re a computer virus, in which case I’ll destroy you faster than you can say “blue screen of death.”
Author Name
Note
while writing the program in the Turbo C++ don’t write the comments like this (// This line includes the header file iostream.h, which provides input/output operations.) this is just for your understanding but you have to write everything in the journal
#include<iostream.h> // This line includes the header file iostream.h, which provides input/output operations.
#include<conio.h>    // This line includes the header file conio.h, which provides console input/output operations.

void swap(float &x,float &y) // This line defines the swap function, which takes two float variables by reference.
{
   float t=x; // This line creates a temporary variable t and assigns it the value of x.
   x=y;       // This line assigns the value of y to x.
   y=t;       // This line assigns the value of t to y.
}

void main() // This line defines the main function, which is the entry point of the program.
{
    void swap(float &,float &); // This line declares the swap function.
    float a,b; // This line declares two float variables called a and b.
    cin>>a>>b; // This line reads two float values from the console and assigns them to a and b.
    cout<<"a="<<a<<"b="<<b<<endl; // This line displays the initial values of a and b.
    swap(a,b); // This line calls the swap function, passing a and b as arguments.
    cout<<"a="<<a<<"b="<<b<<endl; // This line displays the new values of a and b.
    getch(); // This line waits for the user to press a key before closing the console window.
}

Leave a Comment

Scroll to Top