Saturday, September 27, 2014

Create a function template to compare two values and apply this function to data of various type also include string data type with its appropriate function.

#include
#include
#include
template
Tcomp(T a,T b)
{
            return((a>b)?a:b);
}
void comp(char s[],char t[])
{
            int c=strcmp(s,t);
            if(c==0)
                        cout<<"\nThe characters are equal";
            else if(c>0)
                        cout<
            else
                        cout<
}
void main()
{
            clrscr();
            double a,b;
            char c[20],d[20];
            cout<<"\nEnter two numbers: ";
            cin>>a>>b;
            cout<<"\nEnter two strings: ";
            cin>>c>>d;
            int ret =Tcomp(a,b);
            cout<
            comp(c,d);
            getch();

}

No comments:

Post a Comment