sOY wapo ya lo c

#include <stdio.h>

int main() {
    char string[] = "sOY wapo ya lo c";
    int i;

    for (i = 0; string[i] != '\0'; i++) {
        if (string[i] >= 'a' && string[i] <= 'z') {
            string[i] = string[i] - 32;
        } else if (string[i] >= 'A' && string[i] <= 'Z') {
            string[i] = string[i] + 32;
        }
    }

    printf("%s\n", string);

    return 0;
}

Explanation:

  • #include <stdio.h>: Includes the standard input-output library in the program.

  • int main() { ... }: Defines the main function where the execution of the program begins.

  • char string[] = "sOY wapo ya lo c";: Declares and initializes a character array named string with the value "sOY wapo ya lo c".

  • int i;: Declares an integer variable i which will be used as a counter in the loop.

  • for (i = 0; string[i] != '\0'; i++) { ... }: Starts a for loop that iterates through each character of the string array until it reaches the null terminator ('\0'). During each iteration:

    • Checks if the current character is a lowercase letter (string[i] >= 'a' && string[i] <= 'z'). If true, converts it to uppercase by subtracting 32 from its ASCII value.
    • Checks if the current character is an uppercase letter (string[i] >= 'A' && string[i] <= 'Z'). If true, converts it to lowercase by adding 32 to its ASCII value.
  • printf("%s\n", string);: Prints the modified string to the console.

  • return 0;: Indicates successful termination of the main() function.