fork download
  1. #include <stdio.h>
  2.  
  3. // Function to calculate the area of the triangle
  4. double calculate_triangle_area(double b, double h) {
  5. return 0.5 * b * h; // Formula for the area of a triangle
  6. }
  7.  
  8. void main() {
  9. double b = 0.0, h = 0.0, total = 0.0;
  10.  
  11. printf("Input the base value: ");
  12. scanf("%lf", &b);
  13.  
  14. printf("Input the height value: ");
  15. scanf("%lf", &h);
  16.  
  17. if (b > 0 && h > 0) {
  18. total = calculate_triangle_area(b, h);
  19. printf("The area of the triangle is: %.2lf\n", total);
  20. } else {
  21. printf("Base and height must be positive values.\n");
  22. }
  23. }
  24.  
Success #stdin #stdout 0s 5284KB
stdin
Standard input is empty
stdout
Input the base value: Input the height value: Base and height must be positive values.