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
Simpson's Rule is a more accurate method of numerical integration than the method described in class. Using Simpson's Rule, the integral of a function f between a and b is approxim

#questio#A Padovan string P(n) for a natural number n is defined as: P(0) = ‘X’ P(1) = ‘Y’ P(2) = ‘Z’ P(n) = P(n-2) + P(n-3), n>2 where + denotes string concatenation. For a string

You may work in pairs for this assignment. Submit only one project per team; both partners will receive the same grade. Also, you can earn up to 40 points (out of 25) on this assig

Normal 0 false false false EN-US X-NONE X-NONE MicrosoftInternetExplorer4

Use 16 digit credit card numbers that contain 15 digits an 1 check digit. The format of the card number consists of the 15 digits followed by the check digit. The check digit is co

It is a pointer accessible only in the member functions of a struct, class or union type. It points to the object for which the member function is called. Static member functions d

Explain structured programming The principal idea behind structured programming was as easy as the idea of "divide and conquer." A computer program could be regarded as having

A: The inline keyword tells the compiler to substitute the code in the function de_nition for each instance of a function call. Though, substitution takes place only at the compile

Declaration of Variables: Variables are declared as follows: int a; float b;   Assigning value to variables: int a = 100; Declaring and assigning is called ini