Code Competitions

Coding competition

Saturday, 15 June 2013

program to swap 2 numbers using function overloading

#include<iostream.h>
#include<iomanip.h>
#include<conio.h>
void swap(int *a,int *b)
{
    int c;
    c=*a;
    *a=*b;
    *b=c;
}
void swap(float *a,float *b)
{
    float c;
    c=*a;
    *a=*b;
    *b=c;
}
void swap(double *a,double *b)
{
    double c;
    c=*a;
    *a=*b;
    *b=c;
}

void main()
{
    int a,b;
    float c,d;
    double e,f;
    clrscr();
    cout<<"enter the values of a,b for integer";
    cin>>a>>b;
    cout<<"enter the values for c,d ";
    cin>>c>>d;
    cout<<"enter the values for e,f ";
    cin>>e>>f;
    void swap(int *,int *);
    void swap(float *,float *);
    void swap(double *,double *);
    swap(&a,&b);
    swap(&c,&d);
    swap(&e,&f);
    cout<<"\nafter swaping ";
    cout<<"\nvalues of a,b "<<a<<"\t"<<b;
    cout<<" \nvalues of c,d "<<c<<"\t"<<d;
    cout<<"\nvalues of e,f "<<e<<"\t"<<f;
    getch();
}

6 comments:

  1. ALGORITHM PLEASE................................................

    ReplyDelete
  2. i will send you. please send me your email or skype id

    ReplyDelete
  3. this link might be help you C program to swap two numbers

    http://programmergallery.com/c-program/c-program-swap-two-numbers.php

    ReplyDelete