Swap

#include <iostream>
#include <string.h>
using namespace std;
template <class T>
  void Swap(T &x, T &y)
{
  T z;
  strcpy(z,x);
  strcpy(x,y);
  strcpy(y,z);
};
int main() {
char a[20], b[20];
  cin>>a>>b;
  Swap(a,b);
  cout<<a<<" "<<b;
return 0;
}

14 comments:

  1. Replies
    1. #include
      using namespace std;
      template
      T Swap(T x,T y)
      {
      cout<>a>>b;
      Swap(a,b);
      ret

      Delete
  2. #include
    using namespace std;
    template
    T Swap(T x,T y)
    {
    cout<>a>>b;
    Swap(a,b);
    return 0;
    }

    ReplyDelete
  3. #include
    using namespace std;
    template
    T Swap(T x,T y)
    {
    cout<>a>>b;
    Swap(a,b);
    return 0;
    }

    ReplyDelete
  4. This comment has been removed by the author.

    ReplyDelete
  5. #include
    #include
    using namespace std;
    template
    void Swap(T &x,T &y)
    {
    T z;
    strcpy(z,x);
    strcpy(x,y);
    strcpy(y,z);
    };
    int main() {
    char a[20], b[20];
    cin>>a>>b;
    Swap(a,b);
    cout<<a<<" "<<b;
    return 0;
    }

    ReplyDelete
  6. #include
    #include
    using namespace std;
    template
    void Swap(T &x,T &y)
    {
    T z;
    strcpy(z,x);
    strcpy(x,y);
    strcpy(y,z);
    };
    int main() {
    char a[20],b[20];
    cin>>a>>b;
    Swap(a,b);
    cout<<a<<" "<<b;
    return 0;
    }



    works 100%

    ReplyDelete
  7. #include
    #include
    using namespace std;
    template
    void Swap(T &x,T &y)
    {
    T z;
    strcpy(z,x);
    strcpy(x,y);
    strcpy(y,z);
    };
    int main()
    {
    char a[20], b[20];
    cin>>a>>b;
    Swap(a,b);
    cout<<a<<" "<<b;
    return 0;
    }

    ReplyDelete
  8. #include
    #include
    using namespace std;
    //template
    void Swap(T &x,T &y)
    {
    T z;
    strcpy(z,x);
    strcpy(x,y);
    strcpy(y,z);
    };
    int main()
    {
    char a[20], b[20];
    cin>>a>>b;
    Swap(a,b);
    cout<<a<<" "<<b;
    return 0;
    }

    ReplyDelete
  9. #include
    using namespace std;
    template
    void Swap(T &x,T &y)
    {
    T temp;
    temp=x;
    x=y;
    y=temp;
    }
    int main()
    {
    string a,b;
    cin>>a>>b;
    Swap(a,b);
    cout<<a<<" "<<b;
    return 0;
    }




    works 100%

    ReplyDelete