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

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

Posted Date: 9/29/2012 3:52:27 AM | Location : United States







Related Discussions:- C program to swap two numbers using reference arguments, Assignment Help, Ask Question on C program to swap two numbers using reference arguments, Get Answer, Expert's Help, C program to swap two numbers using reference arguments Discussions

Write discussion on C program to swap two numbers using reference arguments
Your posts are moderated
Related Questions
Test scores solution help. Three member variables

write a c program to find input string using strlen(), strcpy(), strcat(),strncat(), strcmp().

Give practice in writing program''s..

A: Use operator overloading to present a friend left-shift operator, operator #include class Fred { public: friend std::ostream& operator ... private: int i_; // onl

Project Description: We are aiming to prepare an industry first in the m-commerce world. M-commerce payment processing programmers required Skills required are C Programmi

A palindrome is a string that reads the same from both the ends. Given a string S convert it to a palindrome by doing character replacement. Your task is to convert S to palindrome

Introduction. In this assignment you are required to revisit the Assignment 1 topic. You will develop a new program which is more sophisticated, in particular, adding more functio

what happens when the following command is used? chmod u=rwx,go=r-x foo

Program is to append the contents of one file to another: void main()    {   clrscr();   fstream file1,file2;   char st1[13],st2[13];/* 13 because a filename canno