Q:

C Program To Find Area of Triangle

belongs to collection: Basic C Programming Examples

0

you have to make this program in the following way:

  • C Program To Find Area of Triangle (Simple Ways)
  • C Program To Find Area of Triangle Using Function
  • C Program To Find Area of Triangle Using Pointer

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

C Program To Find Area of Triangle (Simple Ways)

Algorithm

  • Program Start
  • Declare Variables
  • Input values
  • calculate area of triangle
  • print area of triangle
  • Program End

Program

//C Program To Find Area of Triangle given base and height 

#include <stdio.h>
void main()
{
  int b, h, aot;

  printf("Enter base and hight of a triangle\n");
  scanf("%d %d", &b,&h);

  aot = (b*h)/2;
  printf("Area of the triangle = %d\n", aot);
}

Output

Enter base and hight of a triangle
30
40
Area of the triangle = 60

C Program To Find Area of Triangle Using Function

Algorithm

  • Program Start
  • Declare Variables
  • Input values
  • Calling Function to find area of triangle
  • calculate area of triangle
  • print area of triangle
  • Program End

Program

#include <stdio.h>
int area(int b, int h)
{   int aot;
    aot = (b*h)/2;
    return (aot);
}
void main()
{
  int b, h;

  printf("Enter base and hight of a triangle\n");
  scanf("%d %d", &b,&h);

  printf("Area of the triangle = %d\n",area(b,h));
}

Output

Enter base and hight of a triangle
30
70
Area of the triangle = 1050

 

C Program To Find Area of Triangle Using Pointer

Program

//C Program To Find Area of Triangle Using Pointer 

#include<stdio.h>
int area(int *b, int *h)
{   
    int aot;
    aot = (*b)*(*h)/2;
    return (aot);
}
void main()
{
  int b, h;

  printf("Enter base and hight of a triangle\n");
  scanf("%d %d", &b,&h);

  printf("Area of the triangle = %d\n",area(&b,&h));
}

Output

Enter base and hight of a triangle
10
30
Area of the triangle = 150

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Basic C Programming Examples

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
C Program To Find Area of Rectangle... >>
<< C Program To Find Area of Square...