You are on page 1of 16

Introduc)on

to Programming

Programming

INPUT PROCESSING OUTPUT

Processing - ALOGORITHM
ALGORITHM Series of step by step instruc9ons that solve a problem Make a cup of coee Find the exit of a building Calculate a persons wages

ALGORITHM Calculate Salary


INPUT Hourly Wage Rate and Hours Worked PROCESSING Salary = Rate * Hours OUTPUT Salary

ALGORITHM to code
INPUT int rate; int hours; int salary prinQ(Input hourly rate); scanf( %d ,nrate ) ; print( input hours worked); scanf( %d ,nhours ) ;

ALGORITHM to code
PROCESSING salary = rate * hours;

ALGORITHM to code
OUTPUT prinQ(Salary is %d, salary );

#include <stdio.h> main() { int rate; int hours; int salary; prinQ(Input hourly rate); scanf( %d ,nrate ) ; print( input hours worked); scanf( %d ,nhours ) ; salary = rate * hours;
prinQ(Salary is %d, salary );

C CODE

Control of Flow
The order in which programming statements are executed. SEQUENCE SELECTION REPETITION

SEQUENCE
SEQUENCE programming statements are executed one a`er another, in the order they appear. Star)ng at the top and going down. INPUT Hourly Wage Rate and Hours Worked PROCESSING Salary = Rate * Hours OUTPUT Salary

SELECTION
Some)mes whether an ac)on is carried out depends upon a condi)on being true or false At what age can you drive a car? IF your age is greater than 17 THEN you can drive IF age > 17 THEN you can drive

SELECTION- rela)onal operators


x = 6 y = 10 IF x > y THEN x is greater than y IF x >= y THEN x is greater or equal to y IF x < y THEN x is less than y IF x <= y THEN x is less or equal to y IF x == y THEN x equals y IF x != THEN x does not equal y

SELECTION in C
If (something is true) { //do something } If (3 > 2) { prinQ(3 is greater than 2); }

IF ELSE
IF (something is true) THEN {do this} ELSE {when false do that}

if else in c
if (condi)on) { statements} else { statements}

if else
int i; scanf(%d, i); if (i > o) { prinQ(the number was posi)ve); } else { prinQ(the number was nega)ve or zero); }

You might also like