Skip to content

Instantly share code, notes, and snippets.

@MrBeerBrewer
Created January 18, 2024 17:24
Show Gist options
  • Save MrBeerBrewer/0261d6d669f708d348faf1f6f460fc54 to your computer and use it in GitHub Desktop.
Save MrBeerBrewer/0261d6d669f708d348faf1f6f460fc54 to your computer and use it in GitHub Desktop.
C program to find area of a triangle given three sides - BCA SEMESTER 1 NEP
#include <stdio.h> //Header file is included for Standard input and output
int main() { //This is where the program execution begins
// Declare variables for the sides of the triangle
float base, height;
// Prompt user for input
printf("Enter the base of the triangle: ");
//Store the value that is entered by the user in base variable %f means type cast it to float
scanf("%f", &base);
printf("Enter the height of the triangle: ");
scanf("%f", &height);
// Calculate the area of the triangle
float area = 0.5 * base * height;
// Display the result
//%.4f means print up to 4 decimals
printf("The area of the triangle is: %.4f", area);
return 0;
}
//Enter the base of the triangle: 3.45
//Enter the height of the triangle: 1.234567
//The area of the triangle is: 2.1296
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment