Huwebes, Oktubre 13, 2011

 
          Write a program that asks the user to enter a number n and display the first n odd numbers. Example: if n=5, the first 5 odd numbers are 1, 3, 5, 7 and 9.


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

     int main()
     {
         int m, j;
   
         min("Enter a number: ");
         jee("%d",&j);
   
              for (m=1;m<=j*2;m+=2)
                 {
                 min("%d\n",m);
                 }
         getch ();
         return 0;
     }
                                                                     Sample Output:


                                                                         ▌▌▌Ü ▌▌▌

Problem number 3 ( Iterative Statements )

      Write a program that asks the user to enter a number n and display the first even numbers. Example: if n=5, the first 5 even numbers are 2, 4, 6, 8 and 10.

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

     int main()
     {
         int m, j;
   
         min("Enter a number: ");
         jee("%d",&j);
   
              for ( m = 0; m <= j*2; m+=2)
                  min("%d\n",m);
            
         getch ();
         return 0;
     }
                                                                       Sample Output:


                                                                        ▌▌▌Ü ▌▌▌

Problem number 11

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 min printf
     #define jee scanf

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










                                                                         ▌▌▌Ü ▌▌▌

Problem number 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 min printf
     #define jee scanf

     int main()
     {
         int temp;
   
         min("Enter temperature: ");
         jee("%d",&temp);
   
              if ( temp < 20 )
                  {
                  min("IT'S COLD!");
                  }
             else
             if ( temp > 30 )
                 {
                 min("IT'S HOT!");
                 }
            else
                {
                min("COOL CLIMATE!");
                }
       getch ();
       return 0;
       }
                                                                      Sample Outputs:



                 

                                                                        ▌▌▌Ü ▌▌▌

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:


         
                                                                       ▌▌▌Ü ▌▌▌

Biyernes, Oktubre 7, 2011

Lesson namo saturday(Oct. 8, 2011)

*Review sa DEVC++ lessons...

-Conditional Statements:
◘◘Sample #1:
•Create a program that will display the largest inputted value!

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

   int main()
   {
          int x,y;
      
          printf("Enter value for x :");
          scanf("%d",&x);
          printf("Enter value for y :");
          scanf("%d",&y);
      
          if ( x > y )
          {
                  printf("X is large number - %d\n",x);
          }
          else
          {
                 printf("Y is large number - %d\n",y);
          }
          getch();
          return 0;
}

◘◘Sample #2 :
 •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;
}