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

Introduction To Programming 1

This document introduces programming concepts like algorithms, input/output, and control flow structures. It provides an example algorithm to calculate salary based on hourly rate and hours worked. The algorithm is then coded in C language. It also explains selection and repetition structures like if-else statements to control program flow based on conditions. Relational operators like >, <, == are demonstrated for conditional checking in programs.

Uploaded by

Michael Ulman
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
42 views

Introduction To Programming 1

This document introduces programming concepts like algorithms, input/output, and control flow structures. It provides an example algorithm to calculate salary based on hourly rate and hours worked. The algorithm is then coded in C language. It also explains selection and repetition structures like if-else statements to control program flow based on conditions. Relational operators like >, <, == are demonstrated for conditional checking in programs.

Uploaded by

Michael Ulman
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 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