Reverse the string in C programming with temp variable
Coding:
#include<stdio.h>
#include<conio.h>
void main()
{
char s[100],temp;
int i,j;
clrscr();
printf("\n Enter the string :");
gets(s);
i=0;
j=strlen(s)-1;
while(i < j)
{
temp=s[i];
s[i]=s[j];
s[j--]=temp;
i++;
}
// using built-in function:
//n=strrev(s);
printf("\nReverse string is : %s",s);
getch();
}
Output:
No comments:
Post a Comment