Source code:
/*Write a C code to reverse a string without using any string library functions , e.g. '12345' should be '54321'. */
#include <stdio.h>
#include <string.h>
int main(){
char str[20];
printf("Enter a string:");
//Read String
scanf("%s", str);
int temp;
int i=0,j=0,length;
while (str[j] != '\0')
j++;
j--;
while (i<j) {
temp=str[i];
str[i]=str[j];
str[j]=temp;
i++;
j--;
}
printf("The reverse string:%s",str);
return 0;
}
Output:
No comments:
Post a Comment