#include <stdio.h> void reverse_string(char *str) { int idx=0; char t; while(str[idx]!='\0'){idx++;} int end=idx; { for (int i=0;i<(end/2);i++){ t=str[i]; str[i]=str[--idx]; str[idx]=t; } } } 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