Reverse a String in C

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

MS Excel Logical Functions

Logical functions in Excel are powerful tools that help you make decisions based on conditions. Whether you're comparing values or testi...

Post Count

Loading...