WAP to input a string and display its reverse.

#include<stdio.h>
#include<stdlib.h>
#include<string.h>

void rev(char *,int );
main()
{
char str[10];
int n;
printf("enter your name");

scanf("%s",str);
n=strlen(str);
rev(str,n);
system("pause");
}
void rev(char *str,int n)
{
char rstr[10]={0};
int i;
i=n-1;
while(*str!='NULL')   //WRITE PROPER NULL CHARACTER IF UR COMPILER DOESN'T SUPPORT 'NULL'
{
rstr[i]=*str;
i--;
str++;
}
printf("%s",rstr);
printf("\n");
}
Advertisements

Leave a comment

Filed under TUTORIALS

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s