fork download
  1. #include <stdio.h>
  2. #include <ctype.h>
  3. #include <string.h>
  4.  
  5. void show(char str[100]) { // รับสตริงโดยไม่ใช้ pointer
  6. int length = strlen(str); // ใช้ strlen เพื่อหาความยาวของสตริง
  7. for (int i = 0; i < length; i++) {
  8. if (i % 2 == 0) {
  9. putchar(toupper(str[i])); // แปลงเป็นตัวพิมพ์ใหญ่
  10. } else {
  11. putchar(tolower(str[i])); // แปลงเป็นตัวพิมพ์เล็ก
  12. }
  13. }
  14. putchar('\n'); // ขึ้นบรรทัดใหม่หลังจากแสดงผล
  15. }
  16.  
  17. int main() {
  18. char input[100];
  19.  
  20. printf("กรุณากรอกข้อความ: ");
  21. scanf("%s", input); // รับค่าจากคีย์บอร์ด ไม่จำกัดจำนวนตัวอักษร
  22.  
  23. show(input); // เรียกฟังก์ชัน show เพื่อแสดงข้อมูล
  24. return 0;
  25. }
  26.  
Success #stdin #stdout 0s 5284KB
stdin
Standard input is empty
stdout
กรุณากรอกข้อความ: