//C code for reverse of string using pointer
#include<stdio.h>
#include<string.h>
main()
{
int i,n,j,swap;
char A[100],*P;
clrscr();
printf("Enter character below 100 include space\n");
gets(A);
n=strlen(A);
P=A;
for(i=0;i<n-1;i++)
{
for(j=0;j<n-i-1;j++)
{
if((P+j)<(P+(j+1)))
{
swap=*(P+j);
*(P+j)=*(P+(j+1));
*(P+(j+1))=swap;
}
}
}
printf("The reverse of the string:\n");
for(i=0;i<n;i++)
{
printf("%c",*(P+i));
}
getch();
}
No comments:
Post a Comment