Program for reverse a string in c language.
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char str[20],rev[20];
int i,l,j;
j=0;
clrscr();
printf("enter a string=");
gets(str);
l=strlen(str);
printf("the length of string is =%d\n",l);
for(i=l-1; i>=0; i--)
{
rev[j++]=str[i];
}
rev[j]='\0';
printf("the reverse string is =%s",rev);
getch();
}
■》 Output->
enter a string=ved
the length of string is =3
the reverse string is =dev
Comments
Post a Comment