Reverse string

Program:

#include<stdio.h>
int main()
{
char s1[20],s2[20];
int len=0,i,j;
printf("Enter String: ");
scanf("%s",s1);
while(s1[len]!='\0')
{
len++;
}
for(i=0,j=len-1;i<len;i++,j--)
{
s2[j]=s1[i];
}
s2[len]='\0';
printf("Reverse String: %s",s2);
return 0;
}

Output:



No comments:

Post a Comment

x^y using recursion

Program: #include<stdio.h> int power(int a,int b); int main() { int x,y,ans; printf("Enter x and y:\n "); scanf(...