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
Develop a program to meet the following requirements: 1. Must use at least one function in addition to main (you can use more) 2. Must use selection 3. Must use deference/indire

i wont to make triangle with number but number from the largest possible number to 01 (reversed).

How does free know the size of memory to be deleted.? int *i = (int *)malloc(12); followed by free(i); how did free function call know how much of memory to delete? A: It bas

a program to find the area under the curve y = f(x) between x = a and x = b, integrate y = f(x) between the limits of a and b. The area under a curve between tw

Write a program in C that you will name "divide.exe", to divide one 32-bit twos-complement binary number by another, giving the quotient and the remainder, using the subtract-shift

Convert a COV/CPE (Micosoft Fax Cover Page) file to a TIF image file Project Description: I would like a small API written that will take a COV/CPE file and replaced the corr

smugglers are becoming very smart day by day. Now they have developed a new technique of sending their messages from one smuggler to another. In their new technology, they are send

Integer literal Integer is numbers without fractional parts. e.g. 20       // Decimal 024      // Octal     0x14     // Hexadecimal To indicate long, unsigned,

Why shouldn't Matrix class's interface look like an array-of-array? A: Some people build a Matrix class that has an operator[] that returns a reference to an Array object (or po

write a program to solve e^x