fork download
  1. #include <stdio.h>
  2.  
  3. int main() {
  4. int i;
  5. float temperature;
  6.  
  7. // Loop runs 4 times (i = 1, 2, 3, 4)
  8. for (i = 1; i <= 4; ++i)
  9. {
  10. printf("Enter a temperature: ");
  11. if (scanf("%f", &temperature) != 1) {
  12. printf("Invalid input, exiting loop.\n");
  13. break;
  14. }
  15. printf("The temperature converted to Celsius is %8.2f \n", (temperature - 32.0) * (5.0/9.0));
  16. }
  17.  
  18. return 0;
  19. }
  20.  
Success #stdin #stdout 0.01s 5300KB
stdin
1
2
3
4
stdout
Enter a temperature: The temperature converted to Celsius is   -17.22 
Enter a temperature: The temperature converted to Celsius is   -16.67 
Enter a temperature: The temperature converted to Celsius is   -16.11 
Enter a temperature: The temperature converted to Celsius is   -15.56