Code Competitions

Coding competition

Thursday, 30 May 2013

program to print the string in reverse order

#include<iostream.h>
#include<string.h>
#include<stdio.h>
#include<conio.h>
void main()
{
    int i,j,n;
    char *a[20],temp[40];
    clrscr();
    cout<<" Enter the number of strings ";
    cin>>n;
    for(i=0;i<n;i++)
    {
        a[i]=new char[40];
    }
    cout<<"\n Enter the strings";
    for(i=0;i<n;i++)
    {
        gets(a[i]);
    }
    cout<<"\nentered list of cities is \n";
    for(i=0;i<n;i++)
    {
        puts(a[i]);
    }
    for(i=0;i<n-1;i++)
    {
        for(j=i;j<n-1;j++)
        {
            if(strcmp(a[j+1],a[j]));
            {
                strcpy(temp,a[j]);
                strcpy(a[j],a[j+1]);
                strcpy(a[j+1],temp);
            }
        }
    }
    cout<<"\nlist after sorting ";
    for(i=0;i<n;i++)
    {
        puts(a[i]);
    }
    getch();
}

No comments:

Post a Comment