SlideShare a Scribd company logo
1 of 40
Final Requirement
  To be passed to: Prof. Erwin M.
  Globio



Rubferd Eric F. Medina
Bm10203


                              http://eglobiotraining.com.
PROGRAMING
      A Programing language is used to write computer
programs such as application and utilities.

       Programing allows a programmer or end user to
develop the sets of instructions that constitute a computer
program or software. The role of a programing language can be
described in two ways:

Technical: It is a means for instructing a Computer to perform
Tasks
Conceptual: It is a framework within which we organize our
ideas about things and processes.



                        http://eglobiotraining.com
As an individual, I have learned that programming is a
very broad because it composes many scripts, applications and
can be used to run a program that has been part of the
programming language.

       A programming language should both provide means to
describe primitive data and procedures and means to combine
and abstract those into more complex ones.

        The distinction between data and procedures is not that
clear cut. In many programming languages, procedures can be
passed as data (to be applied to ``real'' data) and sometimes
processed like ``ordinary'' data. Conversely ``ordinary'' data can
be turned into procedures by an evaluation mechanism.

                           http://eglobiotraining.com
At first, programming is confusing because you have so
much to understand about codes that will enable to run a
program. Programming has applications and program
development, the best example for this is the Internet bowser…

       Programming is a creative process done by programmers
to instruct a computer on how to do a task. Fundamentally
programs manipulate numbers and text. These are the building
blocks of all programs.

Programming languages let you use them in different ways, e.g
adding numbers, etc… or storing data on disk for later retrieval.




                           http://eglobiotraining.com
You have to consider languages to run or write your own
program, most demanded language in programming is the DEV C++
(a full-featured Integrated Development Environment (IDE)).

       C++ is one of the most used programming languages in the
world. Also known as "C with Classes".

New to programming or thinking about it? It might surprise you to
know that there are many programmers who program just for fun
and it can lead to a job.




                           http://eglobiotraining.com
SWITCH CASE!
Uses a C Programing Language




                        http://eglobiotraining.com
Switch case statements are a substitute for long if
statements that compare a variable to several
"integral" values ("integral" values are simply values
that can be expressed as an integer, such as the value
of a char). The value of the variable given into switch is
compared to the value following each of the cases, and
when one value matches the value of the variable, the
computer continues executing the program from that
point.




                        http://eglobiotraining.com
The default case is optional, but it is wise to include it
as it handles any unexpected cases. Switch
statements serves as a simple way to write long if
statements when the requirements are met. Often it
can be used to process input from a user.




                         http://eglobiotraining.com
http://eglobiotraining.com
This program will compile, but cannot be run until the
undefined functions are given bodies, but it serves as
a model (albeit simple) for processing input. If you do
not understand this then try mentally putting in if
statements for the case statements. Default simply
skips out of the switch case construction and allows
the program to terminate naturally. If you do not like
that, then you can make a loop around the whole
thing to have it wait for valid input. You could easily
make a few small functions if you wish to test the
code.



                       http://eglobiotraining.com
The switch-case statement is a multi-way decision statement.
Unlike the multiple decision statement that can be created
using if-else, the switch statement evaluates the
conditional expression and tests it against numerous
constant values. The branch corresponding to the value that the
expression matches is taken during execution.
      The value of the expressions in a switch-case statement
must be an ordinal type i.e. integer, char, short, long etc. Float
and double are not allowed.
       The syntax is :




                            http://eglobiotraining.com
The case statements and the default statement can occur in
any order in the switch statement. The default clause is an
optional clause that is matched if none of the constants in
the case statements can be matched.
      Consider the example shown below:




                          http://eglobiotraining.com
Here, if the Grade is 'A' then the output will be:




                            http://eglobiotraining.com
This is because, in the 'C' switch statement, execution
continues on into the next case clause if it is not explicitly
specified that the execution should exit the switch statement.
The correct statement would be:




                          http://eglobiotraining.com
Although the break in the default clause (or in general, after
the last clause) is not necessary, it is good programming
practice to put it in anyway.
       An example where it is better to allow the execution to
continue into the next case statement:




                           http://eglobiotraining.com
Looping Statement!
Uses a C Programing Statement




                          http://eglobiotraining.com
while ( expression )
    statement

In a while loop, the expression is evaluated. If nonzero, the statement executes, and the
expression is evaluated again. This happens over and over until the expression's value is
zero. If the expression is zero the first time it is evaluated, statement is not executed at
all.do
     statement
while ( expression);

A do while loop is just like a plain while loop, except the statement executes before the
expression is evaluated. Thus, the statement will always be evaluated at least once.
         for ( expression1; expression2; expression3 )
    statement

In a for loop, first expression1 is evaluated. Then expression2 is evaluated, and if it is zero
EEL leaves the loop and begins executing instructions after statement. Otherwise the
statement is executed, expression3 is evaluated, and expression2 is evaluated again,
continuing until expression2 is zero.
           You can omit any of the expressions. If you omit expression2, it is
like expression2 is nonzero. while (expression) is the same as for (; expression; ). The
syntax for (;;) creates an endless loop that must be exited using the break statement (or
one of the other statements described below).


                                        http://eglobiotraining.com
Types of Looping
That can be use in Programing

 The for loop construct is used is used to repeat a
  statement or block of statements a specific number of
  times.
 The while loop construct only contains condition.
 The do while, the difference between do while loop
  and other loops is that in the do while loop the
  condition comes after the statement




                                http://eglobiotraining.com
The Break
in Programing

The break keyword is used to terminate a
loop, intermediately bypassing any conditions. The
control will be transferred to the first statement following
the loop block. The break statement can be used to
terminate an infinite loop or to force a loop to end before
its normal termination.




                           http://eglobiotraining.com
My Programs that I use in Programing




               http://eglobiotraining.com
#include<stdio.h>

#include<conio.h>

int main(void)

{

    int n;

    printf("rank yourself from 1-3: ");

    scanf("%d",&n);

    switch(n)

    {

             case 1:

                printf("bad");

                break;

                case 2:

                printf("fair");

                break;

                case 3:

                printf("good");

                break;




                default:

                       printf("invalid");

                       break;




                       }

                       getch();
                                                                Case 1 & Output
                       return 0;

                       }


                                            http://eglobiotraining.com
Here, I program that if you type and enter number 1,
the computer will answer “bad” but if you use number
2, the computer will answer “fair” and last is number 3,
the computer will answer “good” just like in the
previous slide.




                       http://eglobiotraining.com
#include<stdio.h>

#include<conio.h>

int main(void)

{

    int n;

    printf("1+1+2-3= ");

    scanf("%d",&n);

    switch(n)

    {

             case 1:

               printf("correct");

               break;



               default:

                       printf("wrong");

                       break;



                       }

                       getch();

                       return 0;
                                                              Case 2 & Output
                       }


                                          http://eglobiotraining.com
Here in case two. If the answer was correct the
computer were about to answer “correct” but if your
answer is incorrect the computer were program to
answer “wrong”




                      http://eglobiotraining.com
#include<stdio.h>


#include<conio.h>


int main(void)


{


    char n;


    printf("what is the title of the philippine national anthem?na)bayang magiliwnb)lupang hinirangnc)ang bayan ko ");


    scanf("%c",&n);


    switch(n)


    {


         case 'a':


              printf("wrong");


              break;


              case 'b':


              printf("correct");


              break;


              case 'c':


              printf("wrong");


              break;




              default:


                   printf("invalid choice");


                   break;




                   }


                   getch();


                   return 0;
                                                                                                                                        Case 3 & Output
                   }




                                                                                                                    http://eglobiotraining.com
Here in case 3, I do some choices in the question “what
is the tittle of the Philippine national anthem?” the
choices are a)Bayang magiliw, b)lupang hinirang or
c)Ang bayan ko. The correct answer is letter “B” if you
choose the correct letter the computer will answer
“Correct” but if you choose a wrong answer the
computer will answer “wrong” just like in the previous
slide.




                       http://eglobiotraining.com
#include<stdio.h>

#include<conio.h>

int main(void)

{

    int n;

    printf("(4+4)x5= ");

    scanf("%d",&n);

    switch(n)

    {

             case 40:

               printf("correct");

               break;



               default:

                   printf("wrong");

                   break;



                   }

                   getch();

                   return 0;                              Case 4 & Output
                   }



                                      http://eglobiotraining.com
Here in case 4. I use some math question so that the
student will think of what is the correct answer. “40” is
the correct answer if they got it right the computer will
print “CORRECT” but if it is incorrect the computer will
print “WRONG”




                       http://eglobiotraining.com
#include<stdio.h>


#include<conio.h>


int main(void)


{


    char n;


    printf("choose a shape:ncirclenrectanglentriangle ");


    scanf("%c",&n);


    switch(n)


    {


         case 'c':


              printf("Area=(3.1416)(r)(r)");


              break;


              case 'r':


              printf("Area=(length)(width)");


              break;


              case 't':


              printf("Area=1/2(b)(h)");


              break;




              default:


                   printf("invalid");


                   break;




                   }


                   getch();


                   return 0;
                                                                                   Case 5 & Output
                   }




                                                               http://eglobiotraining.com
In the last case, 5. I program the computer to answer
the right area of a given shape. Just like in the previous
slide if you choose circle the computer will answer
“3.1416(r)(r)” so as if you choose other shape.




                        http://eglobiotraining.com
#include<stdio.h>
#include<conio.h>
int main(void)
{
    int ctr;


    for(ctr=-10;ctr<=10;ctr++)
    {
        printf(" %d",ctr);
        }
        getch();
        return 0;
        }                                            Loop 1 & Output
                                 http://eglobiotraining.com
The value of ctr is equal to -10 if the ctr is less than or
equal to 10. the computer will print so on and so forth




                         http://eglobiotraining.com
#include<stdio.h>
#include<conio.h>
int main(void)
{
    int ctr;


    for(ctr=5;ctr<=50;ctr=ctr+5)
    {
        printf(" %d",ctr);
        }
        getch();
        return 0;
        }                                              Loop 2 & Output
                                   http://eglobiotraining.com
The value of ctr is 5 if the ctr is less than or equal to 50
then the value of ctr that is 5 will become 10 because
the program will add another 5 and again and again
and again.




                         http://eglobiotraining.com
#include<stdio.h>
#include<conio.h>
int main(void)
{
    int n=2;
    while(n<=100)
    {
           printf(" %d",n);
           n=n*2;
    }
    getch();
    return 0;
}                                                 Loop 3 & Output
                              http://eglobiotraining.com
The value of n is 2 if the n is less than or equal to 100
then the value of n that is 2 will become 4 because the
program is to be multiplied by 2.




                        http://eglobiotraining.com
#include<stdio.h>
#include<conio.h>
int main(void)
{
    int n;
    n=4;
    do
    {
         printf(" %dth",n);
         n++;
         }while(n<=13);
         getch();
         return 0;
         }
                                                  Loop 4 & Output
                              http://eglobiotraining.com
The value of n is 4 if the n is less than or equal to 13
then the value of n that is 4 will become 5. the
computer will just add 1 to n which is 4.




                         http://eglobiotraining.com
#include<stdio.h>
#include<conio.h>
int main(void)
{
    int a;
    a=1;


    do
    {
         printf(" %d %d",a,a);
         a++;                                             Loop 5 & Output
         }while(a<=9);
         getch();
         return 0;
                           http://www.slideshare.net/rurumedina/funda
         }                 mentals-of-prog-by-rubferd-medina-
                           14685584
                                      http://eglobiotraining.com
The value of a is 1 if the a is less than or equal to 9 then
the value of a that is 1 add 1. it will be repeated and the
next is the other number. Just like in the previous slide.




This file is to be submitted by:
Prof. Erwin M. Globio
http://eglobiotraining.com/

                                   http://eglobiotraining.com

More Related Content

What's hot

Decision making and branching in c programming
Decision making and branching in c programmingDecision making and branching in c programming
Decision making and branching in c programmingPriyansh Thakar
 
Spf Chapter4 Variables
Spf Chapter4 VariablesSpf Chapter4 Variables
Spf Chapter4 VariablesHock Leng PUAH
 
Yeahhhh the final requirement!!!
Yeahhhh the final requirement!!!Yeahhhh the final requirement!!!
Yeahhhh the final requirement!!!olracoatalub
 
Spf Chapter5 Conditional Logics
Spf Chapter5 Conditional LogicsSpf Chapter5 Conditional Logics
Spf Chapter5 Conditional LogicsHock Leng PUAH
 
Decision making using if statement
Decision making using if statementDecision making using if statement
Decision making using if statementCHANDAN KUMAR
 
C Control Statements.docx
C Control Statements.docxC Control Statements.docx
C Control Statements.docxJavvajiVenkat
 
Fundamentals of programming finals.ajang
Fundamentals of programming finals.ajangFundamentals of programming finals.ajang
Fundamentals of programming finals.ajangJaricka Angelyd Marquez
 
Python If Else | If Else Statement In Python | Edureka
Python If Else | If Else Statement In Python | EdurekaPython If Else | If Else Statement In Python | Edureka
Python If Else | If Else Statement In Python | EdurekaEdureka!
 
Unit ii chapter 2 Decision making and Branching in C
Unit ii chapter 2 Decision making and Branching in CUnit ii chapter 2 Decision making and Branching in C
Unit ii chapter 2 Decision making and Branching in CSowmya Jyothi
 
Decision making and loop in C#
Decision making and loop in C#Decision making and loop in C#
Decision making and loop in C#Prasanna Kumar SM
 
C language Unit 2 Slides, UPTU C language
C language Unit 2 Slides, UPTU C languageC language Unit 2 Slides, UPTU C language
C language Unit 2 Slides, UPTU C languageRakesh Roshan
 
Free PHP Book Online | PHP Development in India
Free PHP Book Online | PHP Development in IndiaFree PHP Book Online | PHP Development in India
Free PHP Book Online | PHP Development in IndiaDeepak Rajput
 

What's hot (20)

Php
PhpPhp
Php
 
Decision making and branching in c programming
Decision making and branching in c programmingDecision making and branching in c programming
Decision making and branching in c programming
 
Switch case and looping jam
Switch case and looping jamSwitch case and looping jam
Switch case and looping jam
 
Survelaine murillo ppt
Survelaine murillo pptSurvelaine murillo ppt
Survelaine murillo ppt
 
Spf Chapter4 Variables
Spf Chapter4 VariablesSpf Chapter4 Variables
Spf Chapter4 Variables
 
Yeahhhh the final requirement!!!
Yeahhhh the final requirement!!!Yeahhhh the final requirement!!!
Yeahhhh the final requirement!!!
 
C interview questions and answers
C interview questions and answersC interview questions and answers
C interview questions and answers
 
Spf Chapter5 Conditional Logics
Spf Chapter5 Conditional LogicsSpf Chapter5 Conditional Logics
Spf Chapter5 Conditional Logics
 
Decision making using if statement
Decision making using if statementDecision making using if statement
Decision making using if statement
 
C Control Statements.docx
C Control Statements.docxC Control Statements.docx
C Control Statements.docx
 
Fundamentals of programming finals.ajang
Fundamentals of programming finals.ajangFundamentals of programming finals.ajang
Fundamentals of programming finals.ajang
 
Lesson 4 constant
Lesson 4  constantLesson 4  constant
Lesson 4 constant
 
Python If Else | If Else Statement In Python | Edureka
Python If Else | If Else Statement In Python | EdurekaPython If Else | If Else Statement In Python | Edureka
Python If Else | If Else Statement In Python | Edureka
 
C Constructs (C Statements & Loop)
C Constructs (C Statements & Loop)C Constructs (C Statements & Loop)
C Constructs (C Statements & Loop)
 
Exception handling
Exception handlingException handling
Exception handling
 
Unit ii chapter 2 Decision making and Branching in C
Unit ii chapter 2 Decision making and Branching in CUnit ii chapter 2 Decision making and Branching in C
Unit ii chapter 2 Decision making and Branching in C
 
Decision making and loop in C#
Decision making and loop in C#Decision making and loop in C#
Decision making and loop in C#
 
C language Unit 2 Slides, UPTU C language
C language Unit 2 Slides, UPTU C languageC language Unit 2 Slides, UPTU C language
C language Unit 2 Slides, UPTU C language
 
Free PHP Book Online | PHP Development in India
Free PHP Book Online | PHP Development in IndiaFree PHP Book Online | PHP Development in India
Free PHP Book Online | PHP Development in India
 
Python Flow Control
Python Flow ControlPython Flow Control
Python Flow Control
 

Similar to Fundamentals of prog. by rubferd medina

Fundamentals of programming)
Fundamentals of programming)Fundamentals of programming)
Fundamentals of programming)jakejakejake2
 
Macasu, gerrell c.
Macasu, gerrell c.Macasu, gerrell c.
Macasu, gerrell c.gerrell
 
Switch case and looping
Switch case and loopingSwitch case and looping
Switch case and loopingChaAstillas
 
Switch case and looping kim
Switch case and looping kimSwitch case and looping kim
Switch case and looping kimkimberly_Bm10203
 
Mark asoi ppt
Mark asoi pptMark asoi ppt
Mark asoi pptmark-asoi
 
My programming final proj. (1)
My programming final proj. (1)My programming final proj. (1)
My programming final proj. (1)aeden_brines
 
Switch case and looping
Switch case and loopingSwitch case and looping
Switch case and loopingaprilyyy
 
C language UPTU Unit3 Slides
C language UPTU Unit3 SlidesC language UPTU Unit3 Slides
C language UPTU Unit3 SlidesRakesh Roshan
 
Fundamentals of programming angeli
Fundamentals of programming angeliFundamentals of programming angeli
Fundamentals of programming angelibergonio11339481
 
Decision statements in c language
Decision statements in c languageDecision statements in c language
Decision statements in c languagetanmaymodi4
 
Decision statements in c laguage
Decision statements in c laguageDecision statements in c laguage
Decision statements in c laguageTanmay Modi
 
Final requirement for programming-Bonifacio, Mary Clemence
Final requirement for programming-Bonifacio, Mary ClemenceFinal requirement for programming-Bonifacio, Mary Clemence
Final requirement for programming-Bonifacio, Mary Clemenceclemencebonifacio
 
A brief introduction to C Language
A brief introduction to C LanguageA brief introduction to C Language
A brief introduction to C LanguageMohamed Elsayed
 

Similar to Fundamentals of prog. by rubferd medina (20)

Fundamentals of programming)
Fundamentals of programming)Fundamentals of programming)
Fundamentals of programming)
 
Switch case looping
Switch case loopingSwitch case looping
Switch case looping
 
My final requirement
My final requirementMy final requirement
My final requirement
 
Macasu, gerrell c.
Macasu, gerrell c.Macasu, gerrell c.
Macasu, gerrell c.
 
Switch case and looping
Switch case and loopingSwitch case and looping
Switch case and looping
 
Switch case and looping kim
Switch case and looping kimSwitch case and looping kim
Switch case and looping kim
 
Mark asoi ppt
Mark asoi pptMark asoi ppt
Mark asoi ppt
 
Lecture 1
Lecture 1Lecture 1
Lecture 1
 
Lecture 1
Lecture 1Lecture 1
Lecture 1
 
My programming final proj. (1)
My programming final proj. (1)My programming final proj. (1)
My programming final proj. (1)
 
C++ programming
C++ programmingC++ programming
C++ programming
 
C++ programming
C++ programmingC++ programming
C++ programming
 
Switch case and looping
Switch case and loopingSwitch case and looping
Switch case and looping
 
C language UPTU Unit3 Slides
C language UPTU Unit3 SlidesC language UPTU Unit3 Slides
C language UPTU Unit3 Slides
 
Fundamentals of programming angeli
Fundamentals of programming angeliFundamentals of programming angeli
Fundamentals of programming angeli
 
Decision statements in c language
Decision statements in c languageDecision statements in c language
Decision statements in c language
 
Decision statements in c laguage
Decision statements in c laguageDecision statements in c laguage
Decision statements in c laguage
 
Final requirement for programming-Bonifacio, Mary Clemence
Final requirement for programming-Bonifacio, Mary ClemenceFinal requirement for programming-Bonifacio, Mary Clemence
Final requirement for programming-Bonifacio, Mary Clemence
 
Programming in C
Programming in CProgramming in C
Programming in C
 
A brief introduction to C Language
A brief introduction to C LanguageA brief introduction to C Language
A brief introduction to C Language
 

Fundamentals of prog. by rubferd medina

  • 1. Final Requirement To be passed to: Prof. Erwin M. Globio Rubferd Eric F. Medina Bm10203 http://eglobiotraining.com.
  • 2. PROGRAMING A Programing language is used to write computer programs such as application and utilities. Programing allows a programmer or end user to develop the sets of instructions that constitute a computer program or software. The role of a programing language can be described in two ways: Technical: It is a means for instructing a Computer to perform Tasks Conceptual: It is a framework within which we organize our ideas about things and processes. http://eglobiotraining.com
  • 3. As an individual, I have learned that programming is a very broad because it composes many scripts, applications and can be used to run a program that has been part of the programming language. A programming language should both provide means to describe primitive data and procedures and means to combine and abstract those into more complex ones. The distinction between data and procedures is not that clear cut. In many programming languages, procedures can be passed as data (to be applied to ``real'' data) and sometimes processed like ``ordinary'' data. Conversely ``ordinary'' data can be turned into procedures by an evaluation mechanism. http://eglobiotraining.com
  • 4. At first, programming is confusing because you have so much to understand about codes that will enable to run a program. Programming has applications and program development, the best example for this is the Internet bowser… Programming is a creative process done by programmers to instruct a computer on how to do a task. Fundamentally programs manipulate numbers and text. These are the building blocks of all programs. Programming languages let you use them in different ways, e.g adding numbers, etc… or storing data on disk for later retrieval. http://eglobiotraining.com
  • 5. You have to consider languages to run or write your own program, most demanded language in programming is the DEV C++ (a full-featured Integrated Development Environment (IDE)). C++ is one of the most used programming languages in the world. Also known as "C with Classes". New to programming or thinking about it? It might surprise you to know that there are many programmers who program just for fun and it can lead to a job. http://eglobiotraining.com
  • 6. SWITCH CASE! Uses a C Programing Language http://eglobiotraining.com
  • 7. Switch case statements are a substitute for long if statements that compare a variable to several "integral" values ("integral" values are simply values that can be expressed as an integer, such as the value of a char). The value of the variable given into switch is compared to the value following each of the cases, and when one value matches the value of the variable, the computer continues executing the program from that point. http://eglobiotraining.com
  • 8. The default case is optional, but it is wise to include it as it handles any unexpected cases. Switch statements serves as a simple way to write long if statements when the requirements are met. Often it can be used to process input from a user. http://eglobiotraining.com
  • 10. This program will compile, but cannot be run until the undefined functions are given bodies, but it serves as a model (albeit simple) for processing input. If you do not understand this then try mentally putting in if statements for the case statements. Default simply skips out of the switch case construction and allows the program to terminate naturally. If you do not like that, then you can make a loop around the whole thing to have it wait for valid input. You could easily make a few small functions if you wish to test the code. http://eglobiotraining.com
  • 11. The switch-case statement is a multi-way decision statement. Unlike the multiple decision statement that can be created using if-else, the switch statement evaluates the conditional expression and tests it against numerous constant values. The branch corresponding to the value that the expression matches is taken during execution. The value of the expressions in a switch-case statement must be an ordinal type i.e. integer, char, short, long etc. Float and double are not allowed. The syntax is : http://eglobiotraining.com
  • 12. The case statements and the default statement can occur in any order in the switch statement. The default clause is an optional clause that is matched if none of the constants in the case statements can be matched. Consider the example shown below: http://eglobiotraining.com
  • 13. Here, if the Grade is 'A' then the output will be: http://eglobiotraining.com
  • 14. This is because, in the 'C' switch statement, execution continues on into the next case clause if it is not explicitly specified that the execution should exit the switch statement. The correct statement would be: http://eglobiotraining.com
  • 15. Although the break in the default clause (or in general, after the last clause) is not necessary, it is good programming practice to put it in anyway. An example where it is better to allow the execution to continue into the next case statement: http://eglobiotraining.com
  • 16. Looping Statement! Uses a C Programing Statement http://eglobiotraining.com
  • 17. while ( expression ) statement In a while loop, the expression is evaluated. If nonzero, the statement executes, and the expression is evaluated again. This happens over and over until the expression's value is zero. If the expression is zero the first time it is evaluated, statement is not executed at all.do statement while ( expression); A do while loop is just like a plain while loop, except the statement executes before the expression is evaluated. Thus, the statement will always be evaluated at least once. for ( expression1; expression2; expression3 ) statement In a for loop, first expression1 is evaluated. Then expression2 is evaluated, and if it is zero EEL leaves the loop and begins executing instructions after statement. Otherwise the statement is executed, expression3 is evaluated, and expression2 is evaluated again, continuing until expression2 is zero. You can omit any of the expressions. If you omit expression2, it is like expression2 is nonzero. while (expression) is the same as for (; expression; ). The syntax for (;;) creates an endless loop that must be exited using the break statement (or one of the other statements described below). http://eglobiotraining.com
  • 18. Types of Looping That can be use in Programing  The for loop construct is used is used to repeat a statement or block of statements a specific number of times.  The while loop construct only contains condition.  The do while, the difference between do while loop and other loops is that in the do while loop the condition comes after the statement http://eglobiotraining.com
  • 19. The Break in Programing The break keyword is used to terminate a loop, intermediately bypassing any conditions. The control will be transferred to the first statement following the loop block. The break statement can be used to terminate an infinite loop or to force a loop to end before its normal termination. http://eglobiotraining.com
  • 20. My Programs that I use in Programing http://eglobiotraining.com
  • 21. #include<stdio.h> #include<conio.h> int main(void) { int n; printf("rank yourself from 1-3: "); scanf("%d",&n); switch(n) { case 1: printf("bad"); break; case 2: printf("fair"); break; case 3: printf("good"); break; default: printf("invalid"); break; } getch(); Case 1 & Output return 0; } http://eglobiotraining.com
  • 22. Here, I program that if you type and enter number 1, the computer will answer “bad” but if you use number 2, the computer will answer “fair” and last is number 3, the computer will answer “good” just like in the previous slide. http://eglobiotraining.com
  • 23. #include<stdio.h> #include<conio.h> int main(void) { int n; printf("1+1+2-3= "); scanf("%d",&n); switch(n) { case 1: printf("correct"); break; default: printf("wrong"); break; } getch(); return 0; Case 2 & Output } http://eglobiotraining.com
  • 24. Here in case two. If the answer was correct the computer were about to answer “correct” but if your answer is incorrect the computer were program to answer “wrong” http://eglobiotraining.com
  • 25. #include<stdio.h> #include<conio.h> int main(void) { char n; printf("what is the title of the philippine national anthem?na)bayang magiliwnb)lupang hinirangnc)ang bayan ko "); scanf("%c",&n); switch(n) { case 'a': printf("wrong"); break; case 'b': printf("correct"); break; case 'c': printf("wrong"); break; default: printf("invalid choice"); break; } getch(); return 0; Case 3 & Output } http://eglobiotraining.com
  • 26. Here in case 3, I do some choices in the question “what is the tittle of the Philippine national anthem?” the choices are a)Bayang magiliw, b)lupang hinirang or c)Ang bayan ko. The correct answer is letter “B” if you choose the correct letter the computer will answer “Correct” but if you choose a wrong answer the computer will answer “wrong” just like in the previous slide. http://eglobiotraining.com
  • 27. #include<stdio.h> #include<conio.h> int main(void) { int n; printf("(4+4)x5= "); scanf("%d",&n); switch(n) { case 40: printf("correct"); break; default: printf("wrong"); break; } getch(); return 0; Case 4 & Output } http://eglobiotraining.com
  • 28. Here in case 4. I use some math question so that the student will think of what is the correct answer. “40” is the correct answer if they got it right the computer will print “CORRECT” but if it is incorrect the computer will print “WRONG” http://eglobiotraining.com
  • 29. #include<stdio.h> #include<conio.h> int main(void) { char n; printf("choose a shape:ncirclenrectanglentriangle "); scanf("%c",&n); switch(n) { case 'c': printf("Area=(3.1416)(r)(r)"); break; case 'r': printf("Area=(length)(width)"); break; case 't': printf("Area=1/2(b)(h)"); break; default: printf("invalid"); break; } getch(); return 0; Case 5 & Output } http://eglobiotraining.com
  • 30. In the last case, 5. I program the computer to answer the right area of a given shape. Just like in the previous slide if you choose circle the computer will answer “3.1416(r)(r)” so as if you choose other shape. http://eglobiotraining.com
  • 31. #include<stdio.h> #include<conio.h> int main(void) { int ctr; for(ctr=-10;ctr<=10;ctr++) { printf(" %d",ctr); } getch(); return 0; } Loop 1 & Output http://eglobiotraining.com
  • 32. The value of ctr is equal to -10 if the ctr is less than or equal to 10. the computer will print so on and so forth http://eglobiotraining.com
  • 33. #include<stdio.h> #include<conio.h> int main(void) { int ctr; for(ctr=5;ctr<=50;ctr=ctr+5) { printf(" %d",ctr); } getch(); return 0; } Loop 2 & Output http://eglobiotraining.com
  • 34. The value of ctr is 5 if the ctr is less than or equal to 50 then the value of ctr that is 5 will become 10 because the program will add another 5 and again and again and again. http://eglobiotraining.com
  • 35. #include<stdio.h> #include<conio.h> int main(void) { int n=2; while(n<=100) { printf(" %d",n); n=n*2; } getch(); return 0; } Loop 3 & Output http://eglobiotraining.com
  • 36. The value of n is 2 if the n is less than or equal to 100 then the value of n that is 2 will become 4 because the program is to be multiplied by 2. http://eglobiotraining.com
  • 37. #include<stdio.h> #include<conio.h> int main(void) { int n; n=4; do { printf(" %dth",n); n++; }while(n<=13); getch(); return 0; } Loop 4 & Output http://eglobiotraining.com
  • 38. The value of n is 4 if the n is less than or equal to 13 then the value of n that is 4 will become 5. the computer will just add 1 to n which is 4. http://eglobiotraining.com
  • 39. #include<stdio.h> #include<conio.h> int main(void) { int a; a=1; do { printf(" %d %d",a,a); a++; Loop 5 & Output }while(a<=9); getch(); return 0; http://www.slideshare.net/rurumedina/funda } mentals-of-prog-by-rubferd-medina- 14685584 http://eglobiotraining.com
  • 40. The value of a is 1 if the a is less than or equal to 9 then the value of a that is 1 add 1. it will be repeated and the next is the other number. Just like in the previous slide. This file is to be submitted by: Prof. Erwin M. Globio http://eglobiotraining.com/ http://eglobiotraining.com