This program reverses a given string.
#include <stdio.h>
#include <string.h>
int
main() {
char str[
100], reversedStr[
100];
printf(
"Enter a string: ");
scanf(
"%s", str);
int len =
strlen(str);
for(
int i =
0; i < len; i++) {
reversedStr[i] = str[len - i -
1];
}
reversedStr[len] =
'\0';
printf(
"Reversed string: %s\n", reversedStr);
return
0;
}
No comments:
Post a Comment