Thursday, October 13, 2011

IF Statement (Numer 8)

Write a program segment that will ask the user if he wants to compute the perimeter or the area of a triangle. If the perimeter is wanted, ask the measure of the three sides and compute for the perimeter. If the are is wanted, ask for the measures of the base and height and compute for the area. Display the computed value.




(Solution)


#include<stdio.h>
#include<conio.h>

int CHOICE, PERIMETER, A, B, C, AREA, BASE, HEIGHT;

int main()
{
       printf("This program will get the perimeter and are of Triangle\n");
       printf("Choices\n");
       printf("1.] Perimeter\n");
       printf("2.] Area\n");
       printf("Enter Choice [1 or 2]: ");
       scanf("%d",&choice);

       if (choice == 1)
          {
              printf("Enter Side A: ");
              scanf("%d",&A);
              printf("Enter Side B: ");
              scanf("%d",&B);
              printf("Enter Side C: ");
              scanf("%d",&C);
              PERIMETER = A + B + C;
              printf("The perimeter of the area of a triangle is %d",PERIMETER);
                   }

      if (choice == 2)
          {
              printf("Enter Base: ");
              scanf("%d",&BASE);
              printf("Enter Height: ");
              scanf("%d",&height);
              AREA = (BASE * HEIGHT)/2;
              printf("The area of a triangle is %d",AREA);
                  }
getch();
return 0;
}

0 comments:

Post a Comment