C program to swap two numbers using reference arguments, C/C++ Programming

Assignment Help:

Aim: To implement a program to swap two numbers using reference arguments.

Code:

void swap(int *a, int *b)

{

            int temp;

            temp=*a;

            *a=*b;

            *b=temp;

}

void main()

{

            int a,b;

            clrscr();

            cout<<"Program to swap two variables.";

            cout<<"\nEnter variables:\nA:";

            cin>>a;

            cout<<"B:";

            cin>>b;

            swap(&a,&b);

            cout<<"\nSwapped variables:\n\nA:"<

            cout<<"\nB:"<

            getch();

}

Output:

Program to swap two variables.

Enter variables:

A:5

B:36

Swapped variables:

A:36

B:5


Related Discussions:- C program to swap two numbers using reference arguments

Sorted directory - c++ program, Sorted directory - C++ program: Write ...

Sorted directory - C++ program: Write a program in c to sorting a directory. int main( int argc, char *argv[] ) {     if( argc 3 )         {         cerr

Output, #include void func(int num, b=5) { auto int total=0; static ...

#include void func(int num, b=5) { auto int total=0; static int sum=0; for ( int i=num; i>0 ; i--) total+=i; sum+=total; cout

Inheritance, example of program to add two number

example of program to add two number

Help finish programming assignment, how much is it to fix a small data stru...

how much is it to fix a small data struct in a sorted list that pass itemtypes. all the code is written just logical errors

Program to multiply 2 complex no.s - c++ program, THIS PROGRAM IS TO MULTIP...

THIS PROGRAM IS TO MULTIPLY THE TWO COMPLEX NO.S GIVEN BY THE USER #include #include #include struct complex     {     int real;     int imag;     }; void main()  {  clrs

., what is polymorphism

what is polymorphism

.C# mouse and maze program, .Create a Csharp solution that will show a maze...

.Create a Csharp solution that will show a maze in the user interface and will show a mouse walking through the maze attempting to locate the exit door (the cheese).

Wap for basic salary of employees & calculate net salary, WAP TO ACCEPT THE...

WAP TO ACCEPT THE BASIC SALARY OF EMPLOYEES & CALCULATE NET SALARY   #include stdio.h> #include conio.h>   void main() {                    float Basi

Programs that perform the identical recursive algorithm, Goals For this ass...

Goals For this assignment you will write programs in C and LC-3 assembly code. Both programs will perform the identical recursive algorithm. The goals of this programming assignmen

Arguments passing mechanism, Arguments Passing Mechanism C++ supports th...

Arguments Passing Mechanism C++ supports the following argument passing mechanisms: i).  Pass by value: A copy of the arguments value is made and passed to the called functio

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd