Thursday, 28 May 2015

Displaying city names in reverse order


//printing city names in reverse order
#include<stdio.h>
#include<string.h>
main()
{
   char city[20][20]; int i,num,j;
   printf("enter how many cities want to enter : ");
   scanf("%d",&num);
   printf("enter all city names\n");
   for(i=0;i<=num;i++)
     gets(city[i]);
     
   printf("the reverse order of city names are\n");
   
   /* Here the logic is going to End of Each name and display it in reverse*/
   for(i=0;i<=num;i++)
   {
     j=0;
     
     //Here going to end of name first
     
     while(city[i][j]!='\0')
      j++;
  
    //then displaying it ,Looping from End to first letter making it reversible
      for(j-=1;j>=0;j--)
       printf("%c",city[i][j]);
       printf("\n");
   }
     
}



No comments:

Post a Comment