Algorithm: Step by step procedure of solving a particular problem. Pseudo code: Artificial informal language used to develop algorithms. Flow chart: Graphical.

Slides:



Advertisements
Similar presentations
Algorithm & Flow Charts Decision Making and Looping Presented By Manesh T Course:1090 CS.
Advertisements

Unit 2 The if-else-if LECTURE – 14
Topic 03 Control Statements Programming II/A CMC2522 / CIM2561 Bavy Li.
Understanding Loops Using C Language Week 15 Mr.Omer Salih.
Switch structure Switch structure selects one from several alternatives depending on the value of the controlling expression. The controlling expression.
ספטמבר 04Copyright Meir Kalech1 C programming Language Chapter 2: Control Flow.
If () else statement, switch statement, while () loop, do…while() loop and for( ; ; ) loop 1.
CONTROL STATEMENTS Lakhbir Singh(Lect.IT) S.R.S.G.P.C.G. Ludhiana.
Computer -- Hardware Key board Mouse Input Devices Monitor Printer Output Devices Secondary Storage Devices Input Storage Area Program Storage Area Output.
 Decision making statements Decision making statements if statement if...else statement Nested if...else statement (if...elseif....else Statement) 
Algorithms and Computing Lecture 3 Control Statements By Dr. M. Tahir Khaleeq.
Lecture 4 Introduction to Programming. if ( grade ==‘A’ ) cout
Chapter 13 Control Structures. Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display Control Structures Conditional.
Control Structures. Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display Control Structures Conditional making.
Tutorial ICS431 – Introduction to C.
Repetitive Structures BBS514 Structured Programming (Yapısal Programlama)1.
Chapter 6: Control Structures Computer Programming Skills Second Term Department of Computer Science Foundation Year Program Umm Alqura.
1 Flowchart notation and loops Implementation of loops in C –while loops –do-while loops –for loops Auxiliary Statements used inside the loops –break –continue.
Control Statements (Decision Making)
Lecture 4 Control Structures MIT – AITI What are Control Structures? Control structures are a way to alter the natural sequence of execution in.
Decision making statements. Decision making statements are used to skip or to execute a group of statements based on the result of some condition. The.
C Programming Lecture 7 : Control Structures. Control Structures Conditional statement : if, switch Determine a block of statements to execute depending.
Lecture 2 Control Structure. Relational Operators -- From the previous lecture Relational Operator Meaning == is equal to < is less than > is greater.
Control structures Algorithm Development Conditional Expressions Selection Statements 1.
Lecture 4: C/C++ Control Structures Computer Programming Control Structures Lecture No. 4.
Iterations Very Useful: Ability to repeat a block of code Example:
Program to calculate product of odd numbers b/w 1 and 15 #include main() { int prod = 1, x; for(x = 1; x
CSCI 171 Presentation 5. The while loop Executes a block as long as the condition is true general form: while (condition) { statement 1; statement 2;
ITERATIVE STATEMENTS. Definition Iterative statements (loops) allow a set of instruction to be executed or performed several until condition are met.
Decision Making It is used to change the order of the program based on condition. Categories: – Sequential structure – Selection structure – Iteration.
Introduction to Programming Lecture 7: Repeating Statements.
Fundamentals of Algorithms MCS - 2 Lecture # 5. Representation of Algorithms (continued) Flowcharts.
Statements
Decision Making and Branching (cont.)
We have to discuss following:-  Statements  Statement flow control  Selection statement  Iteration statement.
Asstt. Prof Mandeep Kaur Computer Dept. TOPIC: Control Statements in C language.
BY ILTAF MEHDI (MCS, MCSE, CCNA)1. INSTRUCTOR: ILTAF MEHDI (MCS, MCSE, CCNA, Web Developer) BY ILTAF MEHDI (MCS, MCSE, CCNA)2 Chapter No: 04 “Loops”
Control structures in C by Dr P.Padmanabham Professor (CSE)&Director Bharat Institute of Engineering &Technology Hyderabad Mobile
PGT C Programming1 Week 4 – Repetition Structures / Loops.
Loops and Logic. Making Decisions Conditional operator Switch Statement Variable scope Loops Assertions.
IT CS 200: R EPEATATION Lect. Napat Amphaiphan. T HE ABILITY TO DO THE SAME TASK AGAIN BY AGAIN UNTIL THE CONDITION IS MET LOOP 2.
CC213 Programming Applications Week #2 2 Control Structures Control structures –control the flow of execution in a program or function. Three basic control.
Sesi 0607EKT120/4 Computer Programming Week 5 – Repetition / Loops.
Algorithm & Flow Charts Decision Making and Looping
Flow Charts And Pseudo Codes Grade 12. An algorithm is a complete step-by- step procedure for solving a problem or accomplishing a task.
The following statements are for y = -1; if ( x ) if ( x>0 ) y = 1; else y = 0; A. y= -1 x0 B. y= 0 x0 C. y= 1 x
 Real numbers representation - Floating Point Notation  First C Program  Variables Declaration  Data Types in C ◦ char, short, int, long, float, double,
Module 6 – Decision Control Statements Objectives  Understands Increment/Decrement operators, Conditional and special operators in C  Understands significance.
The Repetition control structure using while loop.
BY ILTAF MEHDI(MCS,MCSE, CCNA) 1. INSTRUCTOR: ILTAF MEHDI (MCS, MCSE, CCNA, Web Developer) BY ILTAF MEHDI(MCS,MCSE, CCNA) 2 Programming Fundamentals Chapter.
Computer -- Hardware Key board Mouse Input Devices Monitor Printer Output Devices Secondary Storage Devices Input Storage Area Program Storage Area Output.
WHILE, DO-WHILE AND FOR LOOPS
‘C’ Programming Khalid Jamal.
EKT120 COMPUTER PROGRAMMING
EKT150 INTRODUCTION TO COMPUTER PROGRAMMING
EKT150 INTRODUCTION TO COMPUTER PROGRAMMING
Lecture 4 - Loops UniMAP EKT120 Sem 1 08/09.
Week 4 – Repetition Structures / Loops
Iteration statement while do-while
מבוא כללי למדעי המחשב תרגול 2
CSI 121 Structure Programming Language Lecture 10: Iteration (Part 1)
Control Structures Lecture 7.
TOPIC 4: REPETITION CONTROL STRUCTURE
CS1100 Computational Engineering
Loops in C.
Chapter 2.1 Repetition.
Aditya Engineering College
Control Statements_2.
Week 3 – Repetition (ctd.)
Control Structure គោលបំណងនៃមេរៀន អ្វីជា Control structure ?
Presentation transcript:

Algorithm: Step by step procedure of solving a particular problem. Pseudo code: Artificial informal language used to develop algorithms. Flow chart: Graphical representation of an algorithm. Algorithm to find whether a number even or odd: Step1: BeginStep1: START Step2: Take a numberStep2: Read num Step3: if the number is divisible by2 thenStep3: if(num%2=0) then print that number is evenprint num is even otherwise print that number is odd otherwise print num is odd Step4: EndStep4: STOP (Algorithm in natural language)(Algorithm by using pseudo code) #include main() { int num; printf(“Enter any number”); scanf(“%d”,&num); if(num%2==0) printf(“%d is even”,num); else printf(%d is odd”,num); } (Program in C language) start read num print num is even stop If num%2=0 print num is odd Flow chart: Yes No No

Flow chart symbols OvalTerminal ParallegramInput/output RectangleProcess DocumentHard copy DiamondDecision CircleConnector Double sided RectangleSub program HexagonIteration TrapezoidManual Operation CylinderMagnetic Disk Storage

TestExpression? Entry False Next statement True Statement-block True simple if: TestExpression? Entry True-blockStatements False False-blockStatements True Next statement if-else: /* check a citizen is eligible for voting */ #include<stdio.h> int main() { int age; int age; printf(“Enter the age : ”); printf(“Enter the age : ”); scanf(“%d”,&age); scanf(“%d”,&age); if(age >= 18) if(age >= 18) printf(“Eligible for voting…”); printf(“Eligible for voting…”); getch(); getch();} /* print a number is even or odd */ #include<stdio.h> int main() { int number; int number; printf(“Enter a number : “); printf(“Enter a number : “); scanf(“%d”, &number); scanf(“%d”, &number); if((number %2) == 0) if((number %2) == 0) printf(“%d is even number.”,number); printf(“%d is even number.”,number); else else printf(“%d is odd number.”,number); printf(“%d is odd number.”,number);}

Testcondition1? Entry Statement-3 True Testcondition2? False Statement-2 Statement-1 True False Next statement nested if…else: /* check whether a year is leap year or not */ #include<stdio.h> int main() { int year; int year; printf("Enter the year ?"); printf("Enter the year ?"); scanf("%d",&year); scanf("%d",&year); if((year %100) == 0) if((year %100) == 0) { if((year % 400) == 0) if((year % 400) == 0) printf("%d is leap year.",year); printf("%d is leap year.",year); else else printf("%d is not leap year.",year); printf("%d is not leap year.",year); } else { } else { if((year % 4) == 0) if((year % 4) == 0) printf("%d is leap year.",year); printf("%d is leap year.",year); else else printf("%d is not leap year.",year); printf("%d is not leap year.",year); } getch(); getch();}

if…else…if : Entry Testcondition1? True Statement-1 True Statement-2 Testcondition2? False True TestconditionN? False Statement-N Next statement /* program to print the grade of student */ #include<stdio.h> int main() { int marks; int marks; printf("Enter marks ? "); printf("Enter marks ? "); scanf("%d", &marks); scanf("%d", &marks); if(marks >= 75) if(marks >= 75) printf("Distinction"); printf("Distinction"); else if(marks >= 60) else if(marks >= 60) printf("First class"); printf("First class"); else if(marks >= 50) else if(marks >= 50) printf("Second class"); printf("Second class"); else if(marks >= 35) else if(marks >= 35) printf("Third class"); printf("Third class"); else else printf("Failed"); printf("Failed");}

switch statement : Entry switchexpression? Next statement /* program to simulate a simple calculator */ #include<stdio.h> int main() { float a,b; float a,b; char opr; char opr; printf("Enter number1 operator number2 : "); printf("Enter number1 operator number2 : "); scanf("%f %c %f",&a,&opr,&b); scanf("%f %c %f",&a,&opr,&b); switch(opr) switch(opr) { case '+': case '+': printf("Sum : %f",(a + b)); printf("Sum : %f",(a + b)); break; break; case '-': case '-': printf("Difference : %f",(a - b)); printf("Difference : %f",(a - b)); break; break; case '*': case '*': printf("Product : %f",(a * b)); printf("Product : %f",(a * b)); break; break; case '/': case '/': printf("Quotient : %f",(a / b)); printf("Quotient : %f",(a / b)); break; break; default: default: printf("Invalid Operation!"); printf("Invalid Operation!"); }} associatestatement associatestatement associatestatement associatestatement value1 value2 valueNdefault Exit ……...

Test Condition ? Body of The loop False true while – (Entry controlled ) Entry Loop Statements Following Statement Test Condition ? Body of The loop False True Entry Following Statement do-while – (Exit controlled ) /* sum of 1 to 10 numbers */ #include<stdio.h> int main() { int i = 1,sum = 0; int i = 1,sum = 0; while(i<=10){ while(i<=10){ sum = sum + i; sum = sum + i; i = i + 1; i = i + 1; } printf(“Total : %d “,sum); printf(“Total : %d “,sum);} /* average of 5 numbers */ #include<stdio.h> int main() { int count = 1; int count = 1; float x, sum = 0; float x, sum = 0; do { do { printf(“x = “); printf(“x = “); scanf(“%f”,&x); scanf(“%f”,&x); sum += x; sum += x; ++ count; ++ count; } while(count <= 5); } while(count <= 5); printf(“Average = %f “, (sum/5)) printf(“Average = %f “, (sum/5))}

for -- Statement Initialization Statement Increment Statement Test Condition ? Body of The loop Entry True Following Statement False /* check whether a number is prime or not */ #include<stdio.h> int main() { int n,i,factors = 0; int n,i,factors = 0; printf("Enter a number : "); printf("Enter a number : "); scanf("%d",&n); scanf("%d",&n); for(i = 1; i <= n; i++) { for(i = 1; i <= n; i++) { if((n % i)==0) ++factors; if((n % i)==0) ++factors; } if (factors == 2) if (factors == 2) printf("%d is prime number.",n); printf("%d is prime number.",n); else else printf("%d is not prime number.",n); printf("%d is not prime number.",n);}