string

#include<iostream>
using namespace std;

int main()
{
    int i;
    char temp[50],str1[10],str2[10],str[20];
    int j,l=0,l1=0;
    cout<<"enter the FIRST string:=";
    cin>>str1;
    cout<<"enter the second string:=";
    cin>>str2;

    cout<<"\ncopy string is:";
    for(i=0;str1[i]!='\0';i++)
    {
        str[i]=str1[i];
       

    }
    str[i]='\0';
    cout<<str;
   

    //compare two string
    i=0;
    while(str1[i]==str2[i] && str1[i]!='\0')
    {
        i++;
        if(str1[i]<str2[i])
        {
            cout<<"\n string 1 < string 2:";
        }
        else if(str1[i]>str2[i])
        {
            cout<<"\n string 1 > string 2";
        }
        else
        {
            cout<<"\n string 1 = string 2";
        }
       
       
    }
   

   
    for(i=0;str1[i]!='\0';i++,j--)
    {
        l1++;
    }
    i=0;
      j =l1- 1;

    while(i<j)

    {

        temp[i]=str1[i];

        str1[i]=str1[j];

        str1[j]=temp[i];
    i++;
    j--;

    }

    cout << "\nReverse string : " <<str1;

    for(i=0;str1[i]!='\0';i++)
    {
        l++;
    }
    for(i=0;str2[i]!='\0';i++)
    {
        l++;
    }
    cout<<"\n length is:="<<l;
    return 0;

}

Comments

Popular posts from this blog

c++ calculator object oriented programming

complex number addition and multiplication using friend function