#include <stdio.h> size_t strlen(char *str) { size_t i = 0; while (str[i]) i++; return i; } void reverse_string(char *str) { size_t len = strlen(str); for (int i = 0; i < len - 1 - i; i++) { char temp = str[i]; str[i] = str[len - 1 - i]; str[len - 1 - i] = temp; } } int main() { char str[101]; fgets(str, sizeof(str), stdin); // Remove newline int i = 0; while (str[i] != '\0') { if (str[i] == '\n') { str[i] = '\0'; break; } i++; } reverse_string(str); printf("%s", str); return 0; }
Test Cases
Test Results
Input
firmware
Expected Output
erawmrif