fork download
  1. #include <stdio.h>
  2.  
  3. int main() {
  4. // เปิดไฟล์ nums.txt เพื่อเขียนข้อมูล
  5. FILE *file = fopen("nums.txt", "w");
  6. fprintf(file, "50\n12\n28\n3\n44\n");
  7.  
  8. // ค้นหาค่าต่ำสุดในไฟล์
  9. int min = 100, x;
  10. file = fopen("nums.txt", "r");
  11. while (fscanf(file, "%d", &x) != EOF) {
  12. if (x < min)
  13. min = x;
  14. }
  15.  
  16. // แสดงค่าต่ำสุด
  17. printf("%d", min);
  18. return 0;
  19. }
  20.  
Success #stdin #stdout 0.03s 25616KB
stdin
Standard input is empty
stdout
#include <stdio.h>

int main() {
    // เปิดไฟล์ nums.txt เพื่อเขียนข้อมูล
    FILE *file = fopen("nums.txt", "w");
    fprintf(file, "50\n12\n28\n3\n44\n");
    fclose(file);

    // ค้นหาค่าต่ำสุดในไฟล์
    int min = 100, x;
    file = fopen("nums.txt", "r");
    while (fscanf(file, "%d", &x) != EOF) {
        if (x < min) 
            min = x;
    }
    fclose(file);

    // แสดงค่าต่ำสุด
    printf("%d", min);
    return 0;
}