Reverse string using function

Program:

#include<stdio.h>
#include<string.h>
void reverse(char s[]);
int main()
{
char str[100];
printf("Enter a string: ");
scanf("%s",str);
reverse(str);
printf("%s",str);
    return 0;
}
void reverse(char s[])
{
  int i,j;
  char temp;
  for(i=0,j=strlen(s)-1;i<strlen(s)/2;i++,j--)
  {
  temp=s[i];
  s[i]=s[j];
  s[j]=temp;
  }
}

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(...