Header Ads Widget

Responsive Advertisement

Ticker

6/recent/ticker-posts

WAP to reverse a string ?

 WAP to reverse a string?  
 #include<stdio.h>  
 #include<string.h>  
 int main()  
  {  
   char string[50], temp;  
   int i, k= 0;  
   printf("\nEnter the string :");  
   gets(string);  
   i = 0;  
   k= strlen(string) - 1;  
   while (i < k)  
  {  
    temp = string[i];  
    string[i] = string[k];  
    string[k] = temp;  
    i++;  
    k--;  
   }  
   printf("\nReverse string is :%s", string);  
   return (0);  
 }  
 Output  
 Enter the string: Asmit  
 Reverse string is : timsA 

 

Post a Comment

0 Comments