Online Compiler C

#include <stdio.h> int main() { char ch; while (scanf("%c", &ch) == 1 && ch != '.') { if (ch >= 'A' && ch <= 'Z') { printf("%c", ch + 32); } else if (ch >= 'a' && ch <= 'z') { printf("%c", ch - 32); } else { printf("%c", ch); } } printf(".\n"); return 0; }
This program reads characters from input one by one until it encounters a period ('.'). For each character, it converts uppercase letters to lowercase, lowercase letters to uppercase, and leaves other characters unchanged. After the loop ends, it prints a period and a newline.

- The loop condition `scanf("%c", &ch) == 1 && ch != '.'` stops reading when a period is entered, but the period itself is not processed or printed inside the loop. The final `printf(".\n")` adds a period at the end, which may not match the expected output if the input period should be included in the transformation.
- Consider what should happen to the period character that ends the input. Should it be printed as part of the output, or should the program stop before printing it? The current code discards the input period and then adds a new one.