fork download
  1. // C code
  2. // This program will calculate the area of a right triangle.
  3. // Developer: Faculty CMIS102
  4. // Date: Jan 31, XXXX
  5. #include <stdio.h>
  6. #include <math.h>
  7. int main ()
  8. {
  9. /* variable definition: */
  10. float base, height, area;
  11. /* Prompt user for base */
  12. printf("Enter the base of the triangle: \n");
  13. // Input the base
  14. scanf("%f", &base);
  15. /* Prompt user for height */
  16. printf("Enter the height of the triangle: \n");
  17. // Input the base
  18. scanf("%f", &height);
  19. // Find the hypotenuse
  20. hypotenuse = sqrt(base^2 + height^2);
  21. // Calculate the Perimeter
  22. perimeter = base + height + hypotenuse;
  23. // Print the result
  24. printf("Perimeter is : %f\n", perimeter);
  25. return 0;
  26. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
15.3
5.1
compilation info
prog.c: In function ‘main’:
prog.c:20:2: error: ‘hypotenuse’ undeclared (first use in this function)
  hypotenuse = sqrt(base^2 + height^2);
  ^~~~~~~~~~
prog.c:20:2: note: each undeclared identifier is reported only once for each function it appears in
prog.c:20:24: error: invalid operands to binary ^ (have ‘float’ and ‘float’)
  hypotenuse = sqrt(base^2 + height^2);
                        ^~~~~~~~~~~
prog.c:22:2: error: ‘perimeter’ undeclared (first use in this function)
  perimeter = base + height + hypotenuse;
  ^~~~~~~~~
prog.c:10:22: warning: unused variable ‘area’ [-Wunused-variable]
  float base, height, area;
                      ^~~~
stdout
Standard output is empty