Pages

Tuesday, October 18, 2011

write a program that will display the following pattern, given the value n

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

main()
{
      int a,b,num;
      p("Enter a number:");
      s("%d",&num);
   
      for(a=1; a < num+1; a++)
      {
               for (b=0; b < a; b++)
              p("*");
               p("\n",a);
               }
               getch();
               return 0;
    

12.Write a program that will read a date(month,day,and year) in integer from and display the date in standard format.

#include<stdio.h>
#include<conio.h>
#define p printf
#define s scanf
int main()
{
    int month,day,yr,A;
 
    p("Enter month:");
    s("%d",&month);
    p("Enter day:");
    s("%d",&day);
    p("Enter year:");
    s("%d",&yr);
 
    if(month==1)
    {
               p("January %d, %d",day,yr);
    }
    else if(month==2)
    {
                p("February %d, %d",day,yr);
                        
    }
    else if(month==3)
    {
                p("March %d, %d",day,yr);        
    }
    else if(month==4)
    {
                p("April %d, %d",day,yr);        
    }
    else if(month==5)
    {
                p("May %d, %d",day,yr);        
    }
    else if(month==6)
    {
                p("June %d, %d",day,yr);        
    }
    else if(month==7)
    {
                p("July %d, %d",day,yr);        
    }
    else if(month==8)
    {
                p("August %d, %d",day,yr);        
    }
    else if(month==9)
    {
                p("September %d, %d",day,yr);        
    }
    else if(month==10)
    {
                p("October %d, %d",day,yr);        
    }
    else if(month==11)
    {
                p("November %d, %d",day ,yr);   
    }
    else if(month==12)
    {
                p("December %d, %d",day ,yr);
    }
 
    getch();
    return 0;
}

Thursday, October 13, 2011

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.

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

Write a program to determine the equivalent grade of each student in a class as follows:
a. Read in the student's name, midterm grade, minor B, and final exam ratings.
b. Determine the final grade of the student by formula: final grade = 0.30 of midterm grade + 0.10 of minor B + 0.60 of final exam.
c. Determine the equivalent grade for the numerical value obtained by the following grading marks:
98 - 100 = 4.00
95 - 97 = 3.75
92 - 94 = 3.50
89 - 91 = 3.25
86 - 88 = 3.00
83 - 85 = 2.75
80 - 82 = 2.50
77 - 79 = 2.25
74 - 76 = 2.00
71 - 73 = 1.75
68 - 70 = 1.50
64 - 67 = 1.25
60 - 63 = 1.00
below 60= 0.00

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

     int main()
     {
         int md, mb, fe;
         float grade;
         char st;
 
         p("Enter student's name: ");
         s("%s",&st);
         p("Enter midterm grade: ");
         s("%d",&md);
         p("Enter minor B: ");
         s("%d",&mb);
         p("Enter final exam: ");
         s("%d",&fe);
 
         grade = ( md * .30 ) + ( mb * .10 ) + ( fe * .60 );
         p("Your final grade is %.2f or equivalent to ",grade);
 
              if( grade >= 98 && grade <= 100)
                  {
                  p("4.00");
                  }
              else
              if( grade >= 95 && grade <= 97)
                  {
                  p("3.75");
                  }
              else
              if( grade >= 92 && grade <= 94)
                  {
                  p("3.50");
                  }
              else
              if( grade >= 89 && grade <= 91)
                  {
                  p("3.25");
                  }
              else
              if( grade >= 86 && grade <= 88)
                  {
                  p("3.00");
                  }
              else
              if( grade >= 83 && grade <= 85)
                  {
                  p("2.75");
                  }
              else
              if( grade >= 80 && grade <= 82)
                  {
                  p("2.50");
                  }
              else
              if( grade >= 77 && grade <= 79)
                  {
                  p("2.25");
                  }
              else
              if( grade >= 74 && grade <= 76)
                  {
                  p("2.00");
                  }
              else
              if( grade >= 71 && grade <= 73)
                  {
                  p("1.75");
                  }
              else
              if( grade >= 68 && grade <= 70)
                  {
                  p("1.50");
                  }
              else
              if( grade >= 64 && grade <= 67)
                  {
                  p("1.25");
                  }
              else
              if( grade >= 60 && grade <= 63)
                  {
                  p("1.00");
                  }
              else
                  {
                  p("0.00");
                  }
         getch ();
         return 0;
      }

Odd Numbers Being Looped

#include
#include
#define s scanf
#define p printf
int main( )
{
int a, b, c;

p("Enter number amount of odd: ");
s("%d", &b);

for(a=1; a<=b; a++)
{
c = a + a - 1;
p("%d\n", c);
}
getch( );
}

Even numbers being looped

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

int main( )
{
int ONE, TWO;
printf("Enter Number: ");
scanf("%d",&TWO);
for (ONE=0; ONE<=TWO; ONE+=2)
{
printf ("%d\n",ONE);
}

getch( );
return 0;
}

Wednesday, October 12, 2011

failed and passed!

#include<stdio.h>
#include<conio.h>
#define p printf
#define s scanf
int grade;
int main()
{


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

solution number 10.

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

int main()
{
    int price, x;
 
    p("Choices:\n");
    p("1.] XL\n");
    p("2.] L\n");
 
 
    p("Enter T-Shirt Size: ");
    s("%d", &x);
 
 
 
    switch(x)
 
    {
    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;
         }

perimeter

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

int choice,p,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);
p = a + b + c;
printf("The perimeter of the area of a triangle is %d",p);
}

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

9. Write a program that will display "IT'S COLD!" if the temperature is less than 20, "IT'S HOT!" if the temperature is greater than 30, "COOL CLIMATE!" otherwise.

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

int main()
{
     int A;
    
     p("enter your temperature:");
     s("%d", &A);
     if(A<=20)
     p("IT'S COLD!");
     else if (A<=30)
     p("COOL CLIMATE!");
     else if(A>=30)
     p("IT'S HOT!");
     getch();
     return 0;
     }
    

1. Create a simple POS program that will compute the quantity order by the customer of a food store. Kindly refer to the sample output below:

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



int main()
{
     int q, total, choice, b, h, c, spag, cash, ch;
    char ans;
    p("*************************************");
    p("\n*        Jobee Food House           *");
    p("\n*************************************");
    p("\n*    Value Meal             Price   *");
    p("\n*************************************");
    p("\n* 1 - Burger, Fries w/Drinks    59  *");
    p("\n* 2 - Hotdog w/Drinks           59  *");
    p("\n* 3 - 1pc Chicken w/Drinks      89  *");
    p("\n* 4 - 2pc Chicken w/Drinks      125 *");
    p("\n* 5 - Spaghetti w/Drinks        59  *");
    p("\n*************************************");
    p("\nEnter Choice:");
    s("%d",&choice);
    switch(choice)
    {
                  case 1:
            p("Enter Quantity:");
            s("%d", &q);
            b = 59;
           
            p("Upgrade [y/n]:");
            s("%s",&ans);
           
            if(ans == 'y')
              {
                   total = q * (b + 15);
    }   
                  
            else
           
            if(ans == 'n')
           
            total = q * b;
            p("Your total bill is:%d", total);
            p("\nEnter Cash:");
            s("%d", &cash);
            ch = cash - total;
            p("Change is:%d", ch);
            break;
           
           
                     case 2:
            p("Enter Quantity:");
            s("%d", &q);
            h = 59;
           
            p("Upgrade [y/n]:");
            s("%s",&ans);
           
            if(ans == 'y')
              {
                   total = q * (h + 15);
    }   
                  
            else
           
            if(ans == 'n')
           
            total = q * h;
            p("Your total bill is:%d", total);
            p("\nEnter Cash:");
            s("%d", &cash);
            ch = cash - total;
            p("Change is:%d", ch);
            break;
           
                           case 3:
            p("Enter Quantity:");
            s("%d", &q);
            c = 89;
           
            p("Upgrade [y/n]:");
            s("%s",&ans);
           
            if(ans == 'y')
              {
                   total = q * (c + 15);
    }   
                  
            else
           
            if(ans == 'n')
           
            total = q * c;
            p("Your total bill is:%d", total);
            p("\nEnter Cash:");
            s("%d", &cash);
            ch = cash - total;
            p("Change is:%d", ch);
            break;
           
          
                              case 4:
            p("Enter Quantity:");
            s("%d", &q);
            c = 125;
           
            p("Upgrade [y/n]:");
            s("%s",&ans);
           
            if(ans == 'y')
              {
                   total = q * (c + 15);
    }   
                  
            else
           
            if(ans == 'n')
           
            total = q * c;
            p("Your total bill is:%d", total);
            p("\nEnter Cash:");
            s("%d", &cash);
            ch = cash - total;
            p("Change is:%d", ch);
            break;
           
           
                                case 5:
            p("Enter Quantity:");
            s("%d", &q);
            spag = 59;
           
            p("Upgrade [y/n]:");
            s("%s",&ans);
           
            if(ans == 'y')
              {
                   total = q * (spag + 15);
    }   
                  
            else
           
            if(ans == 'n')
           
            total = q * c;
            p("Your total bill is:%d", total);
            p("\nEnter Cash:");
            s("%d", &cash);
            ch = cash - total;
            p("Change is:%d", ch);
            break;
            }
    getch();
    return 0;
}