Brijmohan lal Sahu - Facebook
Drop Down MenusCSS Drop Down MenuPure CSS Dropdown Menu

Thursday, September 24, 2015

Program to reverse any string in C

// Program to reverse a string
#include<conio.h>
#include<stdio.h>
#include<string.h>
void main()
{
char name[20],rev[20];
int i,len,j;

clrscr();
printf("\nEnter a string:");                                        

scanf("%s",&name);


printf("\n name entered is: %s",name);

len=strlen(name);

printf("\nLength of string is: %d",len);
i=len-1;
j=0;
while(i>=0)
{
rev[j]=name[i];
printf("\n j=%d  i= %d of %c",j,i,rev[j]);
j=j+1;
i=i-1;
}
printf("\n reverse of string is: ");
for(j=0;j<len;j++)
{
printf("%c",rev[j]);
}

getch();
}

No comments: