0% found this document useful (0 votes)
113 views

CCC101 If Else Switch

Here is a C program to print my first name and last name: #include <stdio.h> int main() { printf("Stefany Caparida"); return 0; } This program uses the printf() function to display the text "Stefany Caparida" on the screen as output. #include <stdio.h> imports the standard input/output library which contains functions like printf(). int main() defines the main function, which is the starting point of execution for the program. printf("Stefany Caparida") displays the text inside the quotation marks to the screen. return 0; indicates that the program finished running successfully by
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
113 views

CCC101 If Else Switch

Here is a C program to print my first name and last name: #include <stdio.h> int main() { printf("Stefany Caparida"); return 0; } This program uses the printf() function to display the text "Stefany Caparida" on the screen as output. #include <stdio.h> imports the standard input/output library which contains functions like printf(). int main() defines the main function, which is the starting point of execution for the program. printf("Stefany Caparida") displays the text inside the quotation marks to the screen. return 0; indicates that the program finished running successfully by
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 82

BASIC GRADES PROGRAM

>=60 >=60
1.Read input from user (it's grade) 1.Read input from user (it's grade)

2.Print "Congratulations!" 2.Print "Failed. Try Again!"


TRUE FALSE
SMVC MSU- IIT-CCS-CA
GIVEN THE CONDITIONS, HOW
WILL YOU WRITE THE CODE?

>=60 >=60
1.Read input from user (it's grade) 1.Read input from user (it's grade)

2.Print "Congratulations!" 2.Print "Failed. Try Again!"


TRUE FALSE
SMVC MSU- IIT-CCS-CA
SMVC MSU- IIT-CCS-CA
C RELATIONAL OPERATORS

A RELATIONAL OPERATOR CHECKS THE RELATIONSHIP BETWEEN TWO OPERANDS. IF THE


RELATION IS TRUE, IT RETURNS 1; IF THE RELATION IS FALSE, IT RETURNS VALUE 0.
SMVC MSU- IIT-CCS-CA
C LOGICAL OPERATORS

AN EXPRESSION CONTAINING LOGICAL OPERATOR RETURNS EITHER 0 OR 1 DEPENDING


UPON WHETHER EXPRESSION RESULTS TRUE OR FALSE.
SMVC MSU- IIT-CCS-CA
C CONTROL FLOW

TRUE FALSE 1. Get grade from user


if grade >= 80
2. If grade is 80 or higher
"EXCELLENT JOB!" TRUE FALSE - print "Excellent Job!"
if grade >= 60
3. If grade is less than 80 but still is
60 or higher
"NOT BAD..." "OH...YOU DIDN'T PASS"
-print "Not bad..."

4. But if the grade is less than 60


-print "Oh...You didn't pass"
SMVC MSU- IIT-CCS-CA
C CONTROL FLOW
SWITCH-CASE

THERE MAY BE TIMES THAT THE CONDITION IS TRUE JUST FOR A SINGLE VALUE

SMVC MSU- IIT-CCS-CA


SWITCH-CASE

Grading System
A: 90-100

Print the range of
B: 80-89 values associated

C: 70-79 with the given


D: 60-69
letter.

F: 0 - 59
SWITCH-CASE

Grading System
A: 90-100

B: 80-89

C: 70-79

D: 60-69

F: 0 - 59
SWITCH-CASE

Switch Case or Switch Statement is also a control mechanism


which allows us to compare a given variable with multiple
cases.

The switch statement evaluates an expression, matching the


expression's value against a series of case clauses, and
executes statements after the first case clause with a
matching value, until a break statement is encountered.
SWITCH-CASE

Grading System
A: 90-100

B: 80-89

C: 70-79

D: 60-69

F: 0 - 59
SWITCH-CASE

Keyword: switch Variable: grade


A,B,C,D,F
SWITCH-CASE

1. open curly brace


2. keyword: case
3. keyword: break
4. colon
5. condition
SWITCH-CASE
SWITCH-CASE
SWITCH-CASE

default: is executed if there is no match


between A,B,C, or D in this example.
SWITCH-CASE
SWITCH-CASE
SHORT QUIZ

1.Write a program that prints the year you were born.


Hint: Include in the printing line the subtraction
calculation between the "current year" and your "age"

2.Write a program that will calculate the rectangle’s


area.
SHORT QUIZ
3. Write a Program that
calculates and prints:
Sn (Sum of the Sequence)

The Program should read from


the user:

n-th Element (An)


Initial Term (A1)
Total Terms (n)

SHORT QUIZ

4.Write a program that checks if 2 numbers


(received from the user) are the same.
If they're the same then print - True
Otherwise, print False

5.Draw the flowchart:


How to will you log in to your facebook account?

CCC 101

INTRODUCTION
GENERAL
CONCEPT
Prepared by

Stefany Mae Caparida Computer Applications


END-USER VS DEVELOPER

END-USER
end-user refers to a user who is interested only in
running simulations and analyzing data

DEVELOPER
developer refers to one who wishes to modify code
and/or develop new code.

SMVC MSU- IIT-CCS-CA Source: Institute Polytechniique de Paris https://tinyurl.com/euvsdev


CCC101
What will we do in this course?

We are the developers in this course.

We will build amazing programming projects.

We will have project exercises.

Students will create something of your own.

SMVC MSU- IIT-CCS-CA


REQUIREMENTS FOR CLASS

Link 1
http://www.codeblocks.org/downl
oads/binaries/#imagesoswindows
48pnglogo-microsoft-windows

IDE Programming Language Link 2


Integrated Development https://www.youtube.com/watch?
Environment is CODEBLOCKS C v=GWJqsmitR2I

SMVC MSU- IIT-CCS-CA


INPUT-PROCESS-OUTPUT

INPUT PROCESS OUTPUT

Automated Teller Machine. We insert our ATM card (input)


and it checks our PIN number (processing) . If it matches
with some, it further continues . We write the amount
(input) , it automatically counts the money (processing) and
gives us the amount we require (output).

SMVC MSU- IIT-CCS-CA


INPUT-PROCESS-OUTPUT

INPUT PROCESS OUTPUT

Microwave Oven. We select the power (input) and it


processes and we get the food which is now hot (output).

SMVC MSU- IIT-CCS-CA


INPUT-PROCESS-OUTPUT

INPUT PROCESS OUTPUT

Calculator. we type a number (input) and then add


operation signs (process) and we get the result after adding
= sign (output)

SMVC MSU- IIT-CCS-CA


UNDERSTANDING WHAT IS A
PROGRAMMING LANGUAGE

Customer [in English]:


What language should I would like to get a
we ask the waitress if croissant and coffee.
we want to order a
croissant and coffee? Waitress: Here you go!

Customer[in English]: Thanks!


waiter customer

SMVC MSU- IIT-CCS-CA


UNDERSTANDING WHAT IS A
PROGRAMMING LANGUAGE
Vous savez, je
I only know
ne parle pas
English!
anglais

customer
waiter
SMVC MSU- IIT-CCS-CA
UNDERSTANDING WHAT IS A
PROGRAMMING LANGUAGE
TRANSLATING
TO FRENCH

I want to get
croissant and
coffee.
TRANSLATOR
GUY

waiter
SMVC MSU- IIT-CCS-CA customer
UNDERSTANDING WHAT IS A
PROGRAMMING LANGUAGE
Translating to
Machine
Language

oh now I get it!

TRANSLATOR
input GUY
HELLO WORLD!
Print:
"HELLO WORLD!" OUTPUT

keyboard
Programming
Language
DISPLAY
SMVC MSU- IIT-CCS-CA
C Programming

Has its own format. Has its own rules.

SMVC MSU- IIT-CCS-CA


entry point, container for block of commands

open and close curly braces; start & end

inputs different functionalities in your program

standard input output


*reading inputs from keyboards
*displaying something on screen (names,etc.)

return 0; command has finished running


successfully

commands end with a semicolon

SMVC MSU- IIT-CCS-CA


Print Print
Hello World! Hello
World!

SMVC MSU- IIT-CCS-CA


Print your First Name and Last Name

SMVC MSU- IIT-CCS-CA


PROCEDURE

In computer programming, a procedure is a set of coded


instructions that tell a computer how to run a program or
calculation. Many different types of programming languages build
a procedure. Depending on the programming language, a
procedure may also be called a subroutine, subprogram or function.
PROCEDURE
In database programming, a stored procedure is a set of
programming code (like PL/SQL) that executes a specific query or
function. This stored procedure is often used to execute one or
more series of commands, search for, insert, update or delete
data in a database.

A procedure is a finite sequence of well- defined instructions, each


of which can be carried out in a finite amount of time.
ALGORITHM

An algorithm is a step-by-step procedure that defines a set of


instructions that must be carried out in a specific order to produce
the desired result.
PSEUDOCODE

Pseudocode (pronounced SOO-doh-kohd) is a detailed yet


readable description of what a computer program or algorithm
must do, expressed in a formally-styled natural language rather
than in a programming language.
PSEUDOCODE

Pseudocode (pronounced SOO-doh-kohd) is a detailed yet


readable description of what a computer program or algorithm
must do, expressed in a formally-styled natural language rather
than in a programming language.
CCC 101 B182 AND B182.1
Once again, we will be meeting every Wednesday
from 4:00 p.m. to 6:00 p.m.

You may use your LAB time to study and implement your
codes. I've already spoken with Sir Ervin about opening
the IOT Lab on Mondays from 2:00 p.m. to 5:00 p.m.
CCC 101 B182 AND B182.1

For the convenience of everybody and to avoid being


crowded in the lab. I have divided the time for the two
sections.

B182 may use the LAB from 2:00pm-3:30pm.


B182.1 may use the LAB from 3:30pm-4:45pm.
CCC 101 B182 AND B182.1
Please understand that CHECKING of the LAB is
scheduled and I will be there.

You may or may not go to the LAB if CHECKING is


not scheduled.

Just be sure to be present during the scheduled


CHECKING .
QUESTION

HOW WILL YOU LOG IN TO YOUR


FACEBOOK ACCOUNT?
ALL ANSWERES ARE CORRECT

Using Desktop
Laptop
Tablet
Smart phone
Using friend's computer
From Internet Cafe
Computer laboratory
etc..
QUESTION

WRITE AN ALGORITHM TO LOG IN TO


YOUR FACEBOOK ACCOUNT.

REMEMBER
AN ALGORITHM IS A STEP-BY-STEP PROCEDURE TO SOLVE A GIVEN PROBLEM.
ALGORITHM

ALGORITHM TO LOG IN TO FACEBOOK ACCOUNT


IN SIMPLE ENGLISH

1. GO TO WWW.FACEBOOK.COM
2. ENTER E-MAIL ID AND PASSWORD
3. CLICK ON LOG IN BUTTON

ALL YOU HAVE TO DO IS WRITE THE CORRECT STEPS IN CORRECT SEQUENCE.


ALGORITHM

WE CAN WRITE ALGORITHMS USING


FLOWCHART
AND
PSEUDOCODE
FLOWCHARTS
6 BASIC SYMBOLS COMMONLY USED IN FLOWCHARTS

TERMINAL PROCESS CONNECTORS


INDICATES THE STARTING INDICATES ANY TYPE OF INTERNAL
ARE USED TO CONNECT
AND ENDING OF A PROGRAM. OPERATIONS LIKE INITIALIZATION
BREAKS IN THE FLOWCHART
CALCULATION ETC.

EXAMPLE: ARE YOU


SINGLE? ANSWER CAN
BE EITHER YES OR NO

INPUT/OUTPUT DECISION
CONTROL FLOW
I/O OPERATION I.E. TAKING INPUT AND USE FOR ASKING QUESTIONS THAT CAN HAVE
EITHER TRUE OR FALSE (YES OR NO) SHOW THE DIRECTION FLOW
SHOWING OUTPUT
AS AN ANSWER

ALGORITHM

ALGORITHM TO LOG IN TO FACEBOOK ACCOUNT


IN SIMPLE ENGLISH

1. GO TO WWW.FACEBOOK.COM
2. ENTER E-MAIL ID AND PASSWORD
3. CLICK ON LOG IN BUTTON

ALL YOU HAVE TO DO IS WRITE THE CORRECT STEPS IN CORRECT SEQUENCE.


FLOWCHARTS
RULES

1. FLOWCHART IS GENERALLY DRAWN FROM TOP TO BOTTOM


2. ALL BOXES OF FLOWCHART MUST BE CONNECTED WITH ARROW
3. ALL FLOWCHART START WITH A TERMINAL OR PROCESS SYMBOL
4. DECISION SYMBOL HAVE TWO EXIT POINTS, ONE FOR YES (TRUE) AND
ANOTHER FOR NO (FALSE)
FLOWCHART EXERCISE
ADD 10 AND 20

ALGORITHM IN SIMPLE ENGLISH

1. INITIALIZE SUM=0 (PROCESS)


2. ENTER THE NUMBERS (I/O)
3. ADD THEM AND STORE THE
RESULT IN SUM (PROCESS)
4. PRINT SUM (I/O)
FLOWCHART EXERCISE
START
ADD 10 AND 20
SUM=0
ALGORITHM IN SIMPLE ENGLISH

ENTER
1. INITIALIZE SUM=0 (PROCESS) 10,20
2. ENTER THE NUMBERS (I/O)
3. ADD THEM AND STORE THE SUM=10+20
RESULT IN SUM (PROCESS)

4. PRINT SUM (I/O)

PRINT

SUM

STOP
FLOWCHART EXERCISE

FIND THE MAX VALUE OUT OF 2 NUMBERS.


FLOWCHART EXERCISE
FIND THE MAX VALUE OUT OF 2 NUMBERS.

ALGORITHM IN SIMPLE ENGLISH

1. INITIALIZE A=0, B=0(PROCESS)


2. ENTER THE NUMBERS A AND B(I/O)
3. COMPARE THE NUMBERS IS A>B?(PROCESS)
3.1 IF YES, DISPLAY A
3.2 IF NO, DISPLAY B
FIND THE MAX VALUE OUT OF 2 NUMBERS.

ALGORITHM IN SIMPLE ENGLISH

1. INITIALIZE A=0, B=0(PROCESS)


2. ENTER THE NUMBERS A AND B(I/O)
3. COMPARE THE NUMBERS, IS A>B?(PROCESS)
3.1 IF YES, DISPLAY A
3.2 IF NO, DISPLAY B

NO
COMMENTS

SMVC MSU- IIT-CCS-CA


MULTILINE COMMENTS

SMVC MSU- IIT-CCS-CA


FORMAT SPECIFICATIONS

SMVC MSU- IIT-CCS-CA


PRACTICE
EXERCISES
https://drive.google.com/file/d/1TZYKikFQE7AY63Dp1EI0oEtJdMbTL3XN/view?usp=sharing

SMVC MSU- IIT-CCS-CA


VARIABLES

1.BOX TYPE SHOE BOX

BALIKBAYAN

2.BOX NAME BOX

3.BOX CONTENT

3. BOX ADDRESS
FOOD STORAGE BOXES
VARIABLES

1.VARIABLE TYPE int, char, float, and double.

2.VARIABLE NAME every variable has its own unique name

3.VARIABLE CONTENT holds a content which is the variable's value

3.VARIABLE ADDRESS unique place where a variable is stored


VARIABLE DECLARATION

1.VARIABLE "Creation"

2.Structure in C language <type> <name>;

age
int age;
temp
double temp;

<variable type> <variable name>;


ASSIGNMENT

1.Put some value in the variable

2.Structure in C language
int age;
30
age=30;

double temp; 26.5


temp = 26.5;
READING INPUT FROM USER
VARIABLE AS INPUT
1.Reading data from user

2.Structure in C language (using Assignment)

80
int grade1;
int grade2;
grade1=80; 100
grade2=100;
printf("Average = %d\n", (grade1+grade2)/2);
READING INPUT FROM USER
VARIABLE AS INPUT
1.Reading data from user
80
2.Structure in C language (using scanf)

int grade1;
int grade2;

scanf("%d",&grade1); 100
scanf("%d",&grade2);

printf("Average = %d\n", (grade1+grade2)/2;


Average = 90
READING INPUT FROM USER

assignment scanf() scanf()


CASTING
5 2
2
<int>

<int> <int> 2.5


<double>
CASTING EXAMPLE
Write a program that gets 3 grades (int) from the user.
The program should calculate and print the EXACT average.
LABORATORY #1
Building Your First Calculator

Write a program that will print on the screen the results of 5 mathematical operations:
Addition (+)
Subtraction (-)
Multiplication (*)
Division (/)
Remainder (%)

Hint: Use format specifications


Write comments.
FAMILYNAME_LAB1ccc101_SECTION
CAPARIDA_LAB1ccc101_B182
LABORATORY #2
Weather Station

1. Write a program that gets from the user a temperature ("double") in Celsius degrees.
The program should calculate and convert the temperature from Celsius degrees to
Fahrenheit degrees and print it.

2. Write a program that gets from the user a temperature ("double") in Fahrenheit
degrees. The program should calculate and convert the temperature from Fahrenheit
degrees to Celsius degrees and print it.

Hint: Use format specifications


Write comments.
FAMILYNAME_LAB2ccc101_SECTION
CAPRIDA_LAB2ccc101_B182
For those who have not yet introduced themselves, just
keep your 1/4 sheet of paper with you. Next meeting, I'll
get to know you better.
I will start checking your laboratory activity
from Sept 19-23.
No Laboratory for B181.1 on Saturday.
We will only meet during lectures, and you can use the IOT Lab
B181 every Wednesday from 8:00-11:00AM.
You can utilize the lab even without my supervision, or let me
know via chat if you're not able to access the lab.
Jot down notes or snap pictures of the lectures.
As a student, it is your job to take notes.
You are allowed to eat snacks during our class.
SEATWORK

Write a program that will print an isoceles triangle.


*
**
****

DRAW THE FLOWCHART TO LOG IN TO FACEBOOK ACCOUNT


SEATWORK
Write a program that will print an isoceles triangle.
*
**
****
DRAW THE FLOWCHART TO LOG IN TO FACEBOOK ACCOUNT

WRITE A PROGRAM THAT GETS AS INPUT (FROM THE USER):


1. CURRENT YEAR
2. YOUR AGE
THE PROGRAM SHOULD CALCULATE AND PRINT THE "YEAR YOU WERE BORN!"

CALCULATE THE AREA OF THE RECTANGLE


ACTIVITY

Write a program that gets as input (from the user):


1. Current Year
2. Your Age
The program should calculate and print the "Year you were Born!"
Solution 1 Solution 2
This activity allows you to see the
importance of using \n and spaces to
achieve a desired output.
SMVC MSU- IIT-CCS-CA
READING INPUT FROM USER
READING INPUT FROM USER
AREA OF THE RECTANGLE

You might also like