Thursday, October 13, 2011

IF Statement (Age)


Write a program that will display "Pretty Young" if age is lesser than 18,
and will display "You Old" if age is  greater than 18.


(Solution)




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

   int main()
   {
          int AGE;
     
          printf("Enter age:");
          scanf("%d",&AGE);
   
          if ( AGE <= 18 )
         {
               printf("Pretty Young!");
         }
         else    
        {
               printf("Your Old!");
       }
       getch();
       return 0;
}

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;
}

IF Statement (Number 10)

Write a program that gives discount of 100 pesos to a costumer if shirt bought is XL and the price is greater than 500; a discount of 50 pesos if the shirt bought is large and the price is greater than 400.


 

(Solution)

#include<stdio.h>
#include<conio.h>
#define s scanf
#define p printf

int main()
{
    int PRICE, EKS;

    p("Choices:\n");
    p("1.] XL\n");
    p("2.] L\n");


    p("Enter T-Shirt Size: ");
    s("%d", &EKS);



    switch(EKS)

    {
    case 1:
   
         p("Enter Price: ");
         s("%d", &PRICE);
   
         if(PRICE>= 500)
     
         p("You Have Discount 100!");
   
         break;
   
   
   
   
    case 2:
              p("Enter Price: ");
              s("%d", &PRICE);
         
              if(PRICE >= 400)
         
              p("You have Discount 50!");
         
              break;
         
   
         default:
                  p("thank you!");
             
                  break;
                  }
         getch();
         return 0;
         }

IF Statement(Grade)

Write a program that will input a student's grade and will display
"Congratulations you PASSED!" if the student's grade is greater than or equal 60. Otherwise "Sorry you FAILED!".
 
#include<stdio.h>
#include<conio.h>
#define p printf
#define s scanf
int GRADE;
int main( )
{


    p("Enter Grade of Student:");
    s("%d",&GRADE);
    if(GRADE >= 60)
    p("Congratulations you PASSED!");
    else
    p("Sorry you FAILED!");
    getch();
    return 0;
}