Lesson 5 - Introduction To Computer Programming
Lesson 5 - Introduction To Computer Programming
PROGRAM
College
College of
of Information
Information &
& Math 112 - Fundamentals of Computing I College of Information & Math 112 - Fundamentals of Computing
Communications
Communications Technology
Technology Ms. Brenda Dy – Po - Benosa Communications Technology Ms. Brenda Dy – Po - Benosa
College of Information & Math 112 - Fundamentals of Computing College of Information & Math 112 - Fundamentals of Computing
Communications Technology Ms. Brenda Dy – Po - Benosa Communications Technology Ms. Brenda Dy – Po - Benosa
10/23/2019
College of Information & Math 112 - Fundamentals of Computing College of Information & Math 112 - Fundamentals of Computing
Communications Technology Ms. Brenda Dy – Po - Benosa Communications Technology Ms. Brenda Dy – Po - Benosa
College of Information & Math 112 - Fundamentals of Computing College of Information & Math 112 - Fundamentals of Computing
Communications Technology Ms. Brenda Dy – Po - Benosa Communications Technology Ms. Brenda Dy – Po - Benosa
10/23/2019
College of Information & Math 112 - Fundamentals of Computing College of Information & Math 112 - Fundamentals of Computing
Communications Technology Ms. Brenda Dy – Po - Benosa Communications Technology Ms. Brenda Dy – Po - Benosa
STRUCTURE OF A C PROGRAM
‘C’ is high level language and is the upgraded version of The basic components of a C program are:
another language (Basic Combined Program Language).
C language was designed at Bell laboratories in the early
main()
1970’s by Dennis Ritchie. pair of braces { }
C being popular in the modern computer world can be declarations and statements
used in Mathematical Scientific, Engineering and
Commercial applications user defined functions
College of Information & Math 112 - Fundamentals of Computing College of Information & Math 112 - Fundamentals of Computing
Communications Technology Ms. Brenda Dy – Po - Benosa Communications Technology Ms. Brenda Dy – Po - Benosa
10/23/2019
COMMENTS
(Multiple Lines)
VARIABLES
PRE-PROCESSOR
DIRECTIVE
College of Information & Math 112 - Fundamentals of Computing College of Information & Math 112 - Fundamentals of Computing
Communications Technology Ms. Brenda Dy – Po - Benosa Communications Technology Ms. Brenda Dy – Po - Benosa
College of Information & Math 112 - Fundamentals of Computing College of Information & Math 112 - Fundamentals of Computing
Communications Technology Ms. Brenda Dy – Po - Benosa Communications Technology Ms. Brenda Dy – Po - Benosa
10/23/2019
College of Information & Math 112 - Fundamentals of Computing College of Information & Math 112 - Fundamentals of Computing
Communications Technology Ms. Brenda Dy – Po - Benosa Communications Technology Ms. Brenda Dy – Po - Benosa
College of Information & Math 112 - Fundamentals of Computing College of Information & Math 112 - Fundamentals of Computing
Communications Technology Ms. Brenda Dy – Po - Benosa Communications Technology Ms. Brenda Dy – Po - Benosa
10/23/2019
College of Information & Math 112 - Fundamentals of Computing College of Information & Math 112 - Fundamentals of Computing
Communications Technology Ms. Brenda Dy – Po - Benosa Communications Technology Ms. Brenda Dy – Po - Benosa
College of Information & Math 112 - Fundamentals of Computing College of Information & Math 112 - Fundamentals of Computing
Communications Technology Ms. Brenda Dy – Po - Benosa Communications Technology Ms. Brenda Dy – Po - Benosa
10/23/2019
College of Information & Math 112 - Fundamentals of Computing College of Information & Math 112 - Fundamentals of Computing
Communications Technology Ms. Brenda Dy – Po - Benosa Communications Technology Ms. Brenda Dy – Po - Benosa
College of Information & Math 112 - Fundamentals of Computing College of Information & Math 112 - Fundamentals of Computing
Communications Technology Ms. Brenda Dy – Po - Benosa Communications Technology Ms. Brenda Dy – Po - Benosa
10/23/2019
College of Information & Math 112 - Fundamentals of Computing College of Information & Math 112 - Fundamentals of Computing
Communications Technology Ms. Brenda Dy – Po - Benosa Communications Technology Ms. Brenda Dy – Po - Benosa
College of Information & Math 112 - Fundamentals of Computing College of Information & Math 112 - Fundamentals of Computing
Communications Technology Ms. Brenda Dy – Po - Benosa Communications Technology Ms. Brenda Dy – Po - Benosa
10/23/2019
College of Information & Math 112 - Fundamentals of Computing College of Information & Math 112 - Fundamentals of Computing
Communications Technology Ms. Brenda Dy – Po - Benosa Communications Technology Ms. Brenda Dy – Po - Benosa
10/23/2019
College of Information & Math 112 - Fundamentals of Computing College of Information & Math 112 - Fundamentals of Computing
Communications Technology Ms. Brenda Dy – Po - Benosa Communications Technology Ms. Brenda Dy – Po - Benosa
College of Information & Math 112 - Fundamentals of Computing College of Information & Math 112 - Fundamentals of Computing
Communications Technology Ms. Brenda Dy – Po - Benosa Communications Technology Ms. Brenda Dy – Po - Benosa
10/23/2019
College of Information & Math 112 - Fundamentals of Computing College of Information & Math 112 - Fundamentals of Computing
Communications Technology Ms. Brenda Dy – Po - Benosa Communications Technology Ms. Brenda Dy – Po - Benosa
College of Information & Math 112 - Fundamentals of Computing College of Information & Math 112 - Fundamentals of Computing
Communications Technology Ms. Brenda Dy – Po - Benosa Communications Technology Ms. Brenda Dy – Po - Benosa
10/23/2019
Integers (int)
Floating-point numbers (float)
Double (double)
Characters (char)
College of Information & Math 112 - Fundamentals of Computing College of Information & Math 112 - Fundamentals of Computing
Communications Technology Ms. Brenda Dy – Po - Benosa Communications Technology Ms. Brenda Dy – Po - Benosa
College of Information & Math 112 - Fundamentals of Computing College of Information & Math 112 - Fundamentals of Computing
Communications Technology Ms. Brenda Dy – Po - Benosa Communications Technology Ms. Brenda Dy – Po - Benosa
10/23/2019
Selection Structures: Conditional Statements if Statement The simple structure of ‘if’ statement is
i. if (< conditional expression>)
statement-1;
(or)
a. if statement. Use to express conditional
ii. if (< conditional expression>)
b. If-else statement. Or 2 way {
expressions. If the given statement-1;
if statement condition is true then it will statement-2;
c. Nested else-if statement. execute the statements statement-3;
otherwise skip the statements. ……………
d. Nested if –else statement.
……………
e. Switch statement. STATEMENT-n
}
College of Information & Math 112 - Fundamentals of Computing College of Information & Math 112 - Fundamentals of Computing
Communications Technology Ms. Brenda Dy – Po - Benosa Communications Technology Ms. Brenda Dy – Po - Benosa
if(<exp>)
Example: if Statement if-else Statement {
Statement-1;
Statement -2;
……………
Statement- n;
Use to execute the either of the }
two statements depending upon else
the value of the expression. {
Statement1;
Statement 2;
……………
Statement- n;
}
College of Information & Math 112 - Fundamentals of Computing College of Information & Math 112 - Fundamentals of Computing
Communications Technology Ms. Brenda Dy – Po - Benosa Communications Technology Ms. Brenda Dy – Po - Benosa
10/23/2019
College of Information & Math 112 - Fundamentals of Computing College of Information & Math 112 - Fundamentals of Computing
Communications Technology Ms. Brenda Dy – Po - Benosa Communications Technology Ms. Brenda Dy – Po - Benosa
College of Information & Math 112 - Fundamentals of Computing College of Information & Math 112 - Fundamentals of Computing
Communications Technology Ms. Brenda Dy – Po - Benosa Communications Technology Ms. Brenda Dy – Po - Benosa
10/23/2019
1. Show the output of the following program lines when the data
entered are 5 and 7.
int m, n;
printf(“Enter two integers: ”);
scanf(“%d%d”, &m, &n);
m = m + 5;
n = 3 * n;
printf(“m = %d\nn = %d\n”, m, n);
College of Information & Math 112 - Fundamentals of Computing College of Information & Math 112 - Fundamentals of Computing
Communications Technology Ms. Brenda Dy – Po - Benosa Communications Technology Ms. Brenda Dy – Po - Benosa
College of Information & Math 112 - Fundamentals of Computing College of Information & Math 112 - Fundamentals of Computing
Communications Technology Ms. Brenda Dy – Po - Benosa Communications Technology Ms. Brenda Dy – Po - Benosa
10/23/2019
College of Information & Math 112 - Fundamentals of Computing College of Information & Math 112 - Fundamentals of Computing
Communications Technology Ms. Brenda Dy – Po - Benosa Communications Technology Ms. Brenda Dy – Po - Benosa
College of Information & Math 112 - Fundamentals of Computing College of Information & Math 112 - Fundamentals of Computing
Communications Technology Ms. Brenda Dy – Po - Benosa Communications Technology Ms. Brenda Dy – Po - Benosa
10/23/2019
College of Information & Math 112 - Fundamentals of Computing College of Information & Math 112 - Fundamentals of Computing
Communications Technology Ms. Brenda Dy – Po - Benosa Communications Technology Ms. Brenda Dy – Po - Benosa
College of Information & Math 112 - Fundamentals of Computing College of Information & Math 112 - Fundamentals of Computing
Communications Technology Ms. Brenda Dy – Po - Benosa Communications Technology Ms. Brenda Dy – Po - Benosa
10/23/2019
Switch Statement
switch(expression)
{
case value1:
A switch statement is used to statement(s);
choose a statement (for a group break;
of statement) among several case value2:
statement(s);
alternatives. The switch break;
statements is useful when a case value3:
variable is to be compared with statement(s);
different constants and in case it break;
default:
is equal to a constant a set of statement(s);
statements are to be executed. }
College of Information & Math 112 - Fundamentals of Computing College of Information & Math 112 - Fundamentals of Computing
Communications Technology Ms. Brenda Dy – Po - Benosa Communications Technology Ms. Brenda Dy – Po - Benosa