Huwebes, Oktubre 13, 2011

Problem number 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.
 

     #include<stdio.h>
     #include<conio.h>
     #define min printf
     #define jee scanf

     int main()
     {
         int peri, s1, s2, s3, base, height;
         char choice;
         float area;
   
         min("What do you want to solve?");
         min("\nP - Perimeter \nA - Area");
         min("\nEnter choice: ");
         jee("%s",&choice);
   
         switch(choice)
          {
                case 'P':
                     {
                     min("Enter side #1: ");
                     jee("%d",&s1);
                     min("Enter side #2: ");
                     jee("%d",&s2);
                     min("Enter side #3: ");
                     jee("%d",&s3);
                 
                     peri = s1 + s2 + s3;

                     min("The perimeter of the triangle is %d",peri);
                     break;
                     }
 
              case 'A':
                     {
                     min("Enter base: ");
                     jee("%d",&base);
                     min("Enter height: ");
                     jee("%d",&height);
               
                     area = (base * height)*.5;
               
                     min("The area of the triangle is %.2f",area);
                     break;
                     }
                     } 
          getch ();
          return 0;
}
                                                                    Sample Outputs:


         
                                                                       ▌▌▌Ü ▌▌▌

Walang komento:

Mag-post ng isang Komento