Looping statement While loop
|
|
- Roland Richardson
- 6 years ago
- Views:
Transcription
1 Looping statement It is also called a Repetitive control structure. Sometimes we require a set of statements to be executed a number of times by changing the value of one or more variables each time to obtain a different result. This type of program execution is called looping. C++ provides the following construct while loop do-while loop for loop While loop Syntax of while loop while(condition) statement(s); The flow diagram indicates that a condition is first evaluated. If the condition is true, the loop body is executed and the condition is re-evaluated. Hence, the loop body is executed repeatedly as long as the condition remains true. As soon as the condition becomes false, it comes out of the loop and goes to the statement next to the while loop. Write a program to print DPSMIS 5 times by using While loop. int i=1; while(i<=5) cout<<"\ndpsmis"; i++; Write a program to print first 5 natural numbers by using While loop. int i=1; while(i<=5) i++;
2 Write a program to print all the even numbers between 1 to 10 by using while loop. int i=2; while(i<=10) i=i+2; Write a program to print all the odd numbers between 10 to 1 using while loop. int i=9; while(i>=1) i=i-2; Write a program to print the following series : upto 25 terms.
3 Long int a=0,b=1,c,t=1; cout<<a<<" "<<b; while(t<=23) c=a+b; cout<<c<<" "; a=b; b=c; i++; Write a program to print the sum of digits of a given number. int num,a,sum=0; cout<<"\nenter the number\t\t\t"; cin>>num; while(num>0) a=num%10; sum=sum+a; num=num/10; cout<<"\nthe sum of digits of the number is\t"<<sum; Write a program to reverse the number.
4 int num,a,rev=0; cout<<"\nenter the number\t"; cin>>num; while(num>0) a=num%10; rev=rev*10+a; // rev is a variable multiply by 10 for place value num=num/10; cout<<"\nthe Reverse number is\t"<<rev; do-while loop Syntax of do-while loop do statements; while (condition); Note : That the loop body is always executed at least once. One important difference between the while loop and the do-while loop the relative ordering of the conditional test and loop body execution. In the while loop, the loop repetition test is performed before each execution the loop body; the loop body is not executed at all if the initial test fail. In the do-while loop, the loop termination test is Performed after each execution of the loop body. hence, the loop body is always executed atleast once. Write a program to print DPSMIS 5 times by using Do While loop. int i=1; do cout<<"\ndpsmis"; i++;
5 while(i<=5); Write a program to print first 5 natural numbers by using Do-While loop. int i=1; do i++; while(i<=5); Write a program to print all the even numbers between 1 to 10 by using do while loop. int i=2; do i=i+2; while(i<=10);
6 Write a program to print all the odd numbers between 10 to 1 by using do while loop. int i=9; //Variable I is initialized with a value 9 do i=i-2; while(i>=1); Write a program to print the following series : upto 25 terms. long int a=0,b=1,c,i=1; cout<<a<<" "<<b; do c=a+b; cout<<c<<" "; a=b; b=c; i++; while(i<=23);
7 for loop It is a count controlled loop in the sense that the program knows in advance how many times the loop is to be executed. syntax of for loop for (initialization; decision; increment/decrement) statement(s); The flow diagram indicates that in for loop three operations take place: Initialization of loop control variable. Ex. int t=1; Testing of loop control variable. Ex. (t<=10) Update the loop control variable either by incrementing or decrementing. Ex. t++; If the TEST-condition is true, the program executes the body of the loop and then the value of loop control variable is updated. Again it checks the TESTcondition and so on. If the TEST-condition is false, it gets out of the loop. Write a program to display name five times. int i; for(i=1; i<=5; i++) cout<< \ndpsmis ; Write a program to find first 10 natural numbers. int i; for(i=1; i<=10; i++) cout<<"\n"<<i;
8 Write a program to input all the even number between 1 to 10. int i; for(i=2; i<=10; i+=2) cout<<"\n"<<i; Write a program to input all the odd numbers between 1 to 10. int i; for(i=1; i<=10; i+=2) cout<<"\n"<<i; Write a program to find the sum of all the even numbers between 1 to 100.
9 int i, sum=0; for(i=2; i<=100; i+=2) sum=sum+i; cout<<"\nsum\t"<<sum; Write a program to input a number and find its factorial. int i,n,fact=1; cout<<"\nenter the number\t\t"; cin>>n; for(i=1; i<=n; i++) fact=fact*i; cout<<"\nfactorial of\t"<<n<<"\tis\t"<<fact; Write a program to find the sum of the following series : 1, 1/2, 1/3,... 1/15 float sum=0,i; for(i=1; i<=15; i++) sum=sum+1/i;
10 cout<<"\nthe sum of the given series is\t"<<sum; Write a program to display the given series : upto 25 terms. int a=0,b=1,c,i; cout<<a<<" "<<b; for(i=1; i<=23; i++) c=a+b; cout<<c<<" "; a=b b=c; Print the following pattern : int i,n; cout<<"\nenter the value of n\t";
11 cin>>n; for(i=1; i<=n; i++) cout<<"*\n"; Nested loop: It is a loop can be nested inside of another loop. Syntax: Nested for loop: for ( init; condition; updation ) for ( init; condition; updation) statement(s); statement(s); // you can put more statements. Print the following pattern : int r,c,i,j; cout<<"\nhow many rows and columns?\t"; cin>>r>>c; for(i=0;i<r;i++) for(j=0;j<c;j++) cout<<"*"; cout<<"\n";
12 int n,i,j; cout<<"\nenter the value of n\t"; cin>>n; for(i=1;i<=n;i++) cout<<"\n"; for(j=1;j<=i;j++) cout<<"*"; cout<<"\n"; int n,i,j; cout<<"\nenter the value of n\t"; cin>>n; for(i=n;i>0;i--)
13 cout<<"\n"; for(j=i;j>0;j--) cout<<"*"; cout<<"\n"; Loop Control Statements/ Jump Statements: Control Statement Description Syntax: break Terminates the loop or switch statement and transfers execution to the statement immediately following the loop or switch. break; continue goto statement Causes the loop to skip the remainder of its body and immediately retest its condition prior to reiterating. It provides an unconditional jump from the goto to a labeled statement in the same function. A label is made of a valid identifier followed by a colon(:). continue; goto label;... label: statement; exit() function The execution of a program can be stopped at any point with exit ( ) and a status code/value can be informed to the calling program, where code is an integer value. The code has a value 0 for correct execution. The value of the code varies depending upon the operating system. It requires <stdlib.h> header file. exit (value) ;
14 Source Code: Output //break #include<iostream.h> #include<conio.h> clrscr(); for(int i=1;i<=10;i++) if(i%4==0) break; //continue #include<iostream.h> #include<conio.h> clrscr(); for(int i=1;i<=10;i++) if(i%4==0) continue; // break and continue #include<iostream.h> #include<conio.h> clrscr(); int x=0,y,sum=0; cout<< Enter a number:: ; cin>>y; while(1) x+=1; if(x>y) break; if(y%x!=0) continue; sum=sum+x; Enter a number::10 Sum of factores:: 18
15 cout<< Sum of factores:: <<sum; //goto statement #include<iostream.h> #include<conio.h> clrscr(); const int maxinput = 3; int i; double number, average, sum=0.0; for(i=1; i<=maxinput; i++) cout<<"enter a number: "; cin>>number; // for negative number, control moves to label jump if(number < 0.0) goto jump; sum += number; // sum = sum+number; Enter a number:3 Enter a number:-1 Sum = 3 Average = 3 jump: average=sum/(i-1); cout<<"sum = "<< sum<<endl; cout<<"average "<<average; //exit function #include<iostream.h> #include<conio.h> #include<stdlib.h> // for exit() clrscr(); cout<<"executed"; exit(0); cout<<"program doesn t exist"; executed
DELHI PUBLIC SCHOOL TAPI
Loops Chapter-1 There may be a situation, when you need to execute a block of code several number of times. In general, statements are executed sequentially: The first statement in a function is executed
More informationComputer Programming: C++
The Islamic University of Gaza Engineering Faculty Department of Computer Engineering Fall 2017 ECOM 2003 Muath i.alnabris Computer Programming: C++ Experiment #4 Loops Part II Contents Loop Control Statement
More information1. Answer the following : a) What do you mean by Open Source Software. Give an example. (2)
THE AIR FORCE SCHOOL Class XI First Terminal Examination 2017-18 Computer Science (083) Time: 3 hrs. M. Marks : 70 General Instructions : (i) All the questions are compulsory. (ii) Programming Language
More informationCHAPTER 9 FLOW OF CONTROL
CHAPTER 9 FLOW OF CONTROL FLOW CONTROL In a program statement may be executed sequentially, selectively or iteratively. Every program language provides constructs to support sequence, selection or iteration.
More informationPrepared by: Shraddha Modi
Prepared by: Shraddha Modi Introduction In looping, a sequence of statements are executed until some conditions for termination of the loop are satisfied. A program loop consist of two segments Body of
More informationControl Structure and Loop Statements
Control Structure and Loop Statements A C/C++ program executes in sequential order that is the way the instructions are written. There are situations when we have to skip certain code in the program and
More informationIntroduction. C provides two styles of flow control:
Introduction C provides two styles of flow control: Branching Looping Branching is deciding what actions to take and looping is deciding how many times to take a certain action. Branching constructs: if
More informationADARSH VIDYA KENDRA NAGERCOIL COMPUTER SCIENCE. Grade: IX C++ PROGRAMMING. Department of Computer Science 1
NAGERCOIL COMPUTER SCIENCE Grade: IX C++ PROGRAMMING 1 C++ 1. Object Oriented Programming OOP is Object Oriented Programming. It was developed to overcome the flaws of the procedural approach to programming.
More informationREPETITION CONTROL STRUCTURE LOGO
CSC 128: FUNDAMENTALS OF COMPUTER PROBLEM SOLVING REPETITION CONTROL STRUCTURE 1 Contents 1 Introduction 2 for loop 3 while loop 4 do while loop 2 Introduction It is used when a statement or a block of
More informationUnit 5. Decision Making and Looping. School of Science and Technology INTRODUCTION
INTRODUCTION Decision Making and Looping Unit 5 In the previous lessons we have learned about the programming structure, decision making procedure, how to write statements, as well as different types of
More informationC++ PROGRAMMING SKILLS Part 2 Programming Structures
C++ PROGRAMMING SKILLS Part 2 Programming Structures If structure While structure Do While structure Comments, Increment & Decrement operators For statement Break & Continue statements Switch structure
More informationDownloaded from
Unit I Chapter -1 PROGRAMMING IN C++ Review: C++ covered in C++ Q1. What are the limitations of Procedural Programming? Ans. Limitation of Procedural Programming Paradigm 1. Emphasis on algorithm rather
More informationUnit 3 Decision making, Looping and Arrays
Unit 3 Decision making, Looping and Arrays Decision Making During programming, we have a number of situations where we may have to change the order of execution of statements based on certain conditions.
More information3/12/2018. Structures. Programming in C++ Sequential Branching Repeating. Loops (Repetition)
Structures Programming in C++ Sequential Branching Repeating Loops (Repetition) 2 1 Loops Repetition is referred to the ability of repeating a statement or a set of statements as many times this is necessary.
More informationBranching is deciding what actions to take and Looping is deciding how many times to take a certain action.
3.0 Control Statements in C Statements The statements of a C program control the flow of program execution. A statement is a command given to the computer that instructs the computer to take a specific
More informationSample Paper - II Subject Computer Science
Sample Paper - II Subject Computer Science Max Marks 70 Duration 3 hrs Note:- All questions are compulsory Q1) a) What is significance of My Computer? 2 b) Explain different types of operating systems.
More informationCHAPTER 4 CONTROL STRUCTURES
CHAPTER 4 CONTROL STRUCTURES 1 Control Structures A program is usually not limited to a linear sequence of instructions. During its process it may deviate, repeat code or take decisions. For that purpose,
More informationCHRIST THE KING BOYS MATRIC HR. SEC. SCHOOL, KUMBAKONAM CHAPTER 9 C++
CHAPTER 9 C++ 1. WRITE ABOUT THE BINARY OPERATORS USED IN C++? ARITHMETIC OPERATORS: Arithmetic operators perform simple arithmetic operations like addition, subtraction, multiplication, division etc.,
More informationVOLUME II CHAPTER 9 INTRODUCTION TO C++ HANDS ON PRACTICE PROGRAMS
VOLUME II CHAPTER 9 INTRODUCTION TO C++ HANDS ON PRACTICE PROGRAMS 1. Write C++ programs to interchange the values of two variables. a. Using with third variable int n1, n2, temp; cout
More informationDECISION CONTROL AND LOOPING STATEMENTS
DECISION CONTROL AND LOOPING STATEMENTS DECISION CONTROL STATEMENTS Decision control statements are used to alter the flow of a sequence of instructions. These statements help to jump from one part of
More informationProgramming Fundamentals
Programming Fundamentals Programming Fundamentals Instructor : Zuhair Qadir Lecture # 11 30th-November-2013 1 Programming Fundamentals Programming Fundamentals Lecture # 11 2 Switch Control substitute
More informationDHA Suffa University CS 103 Object Oriented Programming Fall 2015 Lab #01: Introduction to C++
DHA Suffa University CS 103 Object Oriented Programming Fall 2015 Lab #01: Introduction to C++ Objective: To Learn Basic input, output, and procedural part of C++. C++ Object-orientated programming language
More informationC++ is case sensitive language, meaning that the variable first_value, First_Value or FIRST_VALUE will be treated as different.
C++ Character Set a-z, A-Z, 0-9, and underscore ( _ ) C++ is case sensitive language, meaning that the variable first_value, First_Value or FIRST_VALUE will be treated as different. Identifier and Keywords:
More informationMODULE 2: Branching and Looping
MODULE 2: Branching and Looping I. Statements in C are of following types: 1. Simple statements: Statements that ends with semicolon 2. Compound statements: are also called as block. Statements written
More information2. Distinguish between a unary, a binary and a ternary operator. Give examples of C++ operators for each one of them.
1. Why do you think C++ was not named ++C? C++ is a super set of language C. All the basic features of C are used in C++ in their original form C++ can be described as C+ some additional features. Therefore,
More informationSample Paper Class XI Subject Computer Sience UNIT TEST II
Sample Paper Class XI Subject Computer Sience UNIT TEST II (General OOP concept, Getting Started With C++, Data Handling and Programming Paradigm) TIME: 1.30 Hrs Max Marks: 40 ALL QUESTIONS ARE COMPULSURY.
More informationI SEMESTER EXAM : : XI :COMPUTER SCIENCE : MAX MARK a) What is the difference between Hardware and Software? Give one example for each.
I SEMESTER EXAM : : XI :COMPUTER SCIENCE : MAX MARK 70. a) What is the difference between Hardware and Software? Give one example for each. b) Give two differences between primary and secondary memory.
More informationSELECTION STATEMENTS:
UNIT-2 STATEMENTS A statement is a part of your program that can be executed. That is, a statement specifies an action. Statements generally contain expressions and end with a semicolon. Statements that
More informationCHAPTER : 9 FLOW OF CONTROL
CHAPTER 9 FLOW OF CONTROL Statements-Statements are the instructions given to the Computer to perform any kind of action. Null Statement-A null statement is useful in those case where syntax of the language
More information1. FIBONACCI SERIES. Write a C++ program to generate the Fibonacci for n terms. To write a C++ program to generate the Fibonacci for n terms.
PROBLEM: 1. FIBONACCI SERIES Write a C++ program to generate the Fibonacci for n terms. AIM: To write a C++ program to generate the Fibonacci for n terms. PROGRAM CODING: #include #include
More informationC++ Programming Lecture 7 Control Structure I (Repetition) Part I
C++ Programming Lecture 7 Control Structure I (Repetition) Part I By Ghada Al-Mashaqbeh The Hashemite University Computer Engineering Department while Repetition Structure I Repetition structure Programmer
More informationComputers Programming Course 7. Iulian Năstac
Computers Programming Course 7 Iulian Năstac Recap from previous course Operators in C Programming languages typically support a set of operators, which differ in the calling of syntax and/or the argument
More informationLoops / Repetition Statements
Loops / Repetition Statements Repetition statements allow us to execute a statement multiple times Often they are referred to as loops C has three kinds of repetition statements: the while loop the for
More informationAll copyrights reserved - KV NAD, Aluva. Dinesh Kumar Ram PGT(CS) KV NAD Aluva
All copyrights reserved - KV NAD, Aluva Dinesh Kumar Ram PGT(CS) KV NAD Aluva Overview Looping Introduction While loops Syntax Examples Points to Observe Infinite Loops Examples using while loops do..
More informationSample Paper -V Subject Computer Science Time: 3Hours Note. (i) All questions are compulsory. Maximum Marks: 70 Q.No.1 a. Write the header file for the given function 2 abs(), isdigit(), sqrt(), setw()
More informationSubject: PIC Chapter 2.
02 Decision making 2.1 Decision making and branching if statement (if, if-, -if ladder, nested if-) Switch case statement, break statement. (14M) 2.2 Decision making and looping while, do, do-while statements
More informationc++ Solutions eedsohag.epizy.com Ahmed Ali
c++ s Ahmed Ali int main(int argc, char *argv[]) int age; age=10; cout
More informationChapter 4: Control structures. Repetition
Chapter 4: Control structures Repetition Loop Statements After reading and studying this Section, student should be able to Implement repetition control in a program using while statements. Implement repetition
More informationFlow Control. CSC215 Lecture
Flow Control CSC215 Lecture Outline Blocks and compound statements Conditional statements if - statement if-else - statement switch - statement? : opertator Nested conditional statements Repetitive statements
More informationIntroduction to Algorithms and Programming (COMP151)
Introduction to Algorithms and Programming (COMP151) A Student's Manual for Practice Exercises Dr. Mohamed Aissa m.issa@unizwa.edu.om 11i13 Summer 2014 Practice Exercises #1 Introduction Page 2 Practice
More informationn Group of statements that are executed repeatedly while some condition remains true
Looping 1 Loops n Group of statements that are executed repeatedly while some condition remains true n Each execution of the group of statements is called an iteration of the loop 2 Example counter 1,
More informationDownloaded from
Unit-II Data Structure Arrays, Stacks, Queues And Linked List Chapter: 06 In Computer Science, a data structure is a particular way of storing and organizing data in a computer so that it can be used efficiently.
More informationProgramming Basics and Practice GEDB029 Decision Making, Branching and Looping. Prof. Dr. Mannan Saeed Muhammad bit.ly/gedb029
Programming Basics and Practice GEDB029 Decision Making, Branching and Looping Prof. Dr. Mannan Saeed Muhammad bit.ly/gedb029 Decision Making and Branching C language possesses such decision-making capabilities
More informationChapter 4: Control structures
Chapter 4: Control structures Repetition Loop Statements After reading and studying this Section, student should be able to Implement repetition control in a program using while statements. Implement repetition
More informationChapter4: Data Structures. Data: It is a collection of raw facts that has implicit meaning.
Chapter4: s Data: It is a collection of raw facts that has implicit meaning. Data may be single valued like ID, or multi valued like address. Information: It is the processed data having explicit meaning.
More informationJava Loop Control. Programming languages provide various control structures that allow for more complicated execution paths.
Loop Control There may be a situation when you need to execute a block of code several number of times. In general, statements are executed sequentially: The first statement in a function is executed first,
More informationUNIT IV INTRODUCTION TO C
UNIT IV INTRODUCTION TO C 1. OVERVIEW OF C C is portable, structured programming language. It is robust, fast.extensible. It is used for complex programs. The root of all modern language is ALGOL (1960).
More informationFUNDAMENTALS OF COMPUTING & COMPUTER PROGRAMMING UNIT IV INTRODUCTION TO C
FUNDAMENTALS OF COMPUTING & COMPUTER PROGRAMMING UNIT IV INTRODUCTION TO C Overview of C Constants, Variables and Data Types Operators and Expressions Managing Input and Output operators Decision Making
More informationOther operators. Some times a simple comparison is not enough to determine if our criteria has been met.
Lecture 6 Other operators Some times a simple comparison is not enough to determine if our criteria has been met. For example: (and operation) If a person wants to login to bank account, the user name
More informationMatrix-Vector Multiplication using friend function
Ex.No.1 13.07.2012 Matrix-Vector Multiplication using friend function Aim: To write C++ program to define matrix and vector class, to use function with default argument and to do matrix-vector multiplication
More informationBasic Statements in C++ are constructed using tokens. The different statements are
CHAPTER 3 BASIC STATEMENTS Basic Statements in C++ are constructed using tokens. The different statements are Input/output Declaration Assignment Control structures Function call Object message Return
More informationNumerical Computing in C and C++ Jamie Griffin. Semester A 2017 Lecture 2
Numerical Computing in C and C++ Jamie Griffin Semester A 2017 Lecture 2 Visual Studio in QM PC rooms Microsoft Visual Studio Community 2015. Bancroft Building 1.15a; Queen s W207, EB7; Engineering W128.D.
More informationClass 9. Choose the correct answer:
Class 9 Choose the correct answer: 1. Which one of the following is a looping statement? a) if b) break c) continue d) for 2. A sequence of instructions that may be repeatedly executed is a) Loop b) if
More informationAccelerating Information Technology Innovation
Accelerating Information Technology Innovation http://aiti.mit.edu Cali, Colombia Summer 2012 Lección 03 Control Structures Agenda 1. Block Statements 2. Decision Statements 3. Loops 2 What are Control
More informationThere are algorithms, however, that need to execute statements in some other kind of ordering depending on certain conditions.
Introduction In the programs that we have dealt with so far, all statements inside the main function were executed in sequence as they appeared, one after the other. This type of sequencing is adequate
More informationLoops and Files. Chapter 04 MIT 12043, Fundamentals of Programming By: S. Sabraz Nawaz
Loops and Files Chapter 04 MIT 12043, Fundamentals of Programming By: S. Sabraz Nawaz Chapter Topics o The Increment and Decrement Operators o The while Loop o Shorthand Assignment Operators o The do-while
More informationLECTURE NOTES ON PROGRAMMING FUNDAMENTAL USING C++ LANGUAGE
Department of Software The University of Babylon LECTURE NOTES ON PROGRAMMING FUNDAMENTAL USING C++ LANGUAGE By Collage of Information Technology, University of Babylon, Iraq Samaher_hussein@yahoo.com
More informationLecture 7: General Loops (Chapter 7)
CS 101: Computer Programming and Utilization Jul-Nov 2017 Umesh Bellur (cs101@cse.iitb.ac.in) Lecture 7: General Loops (Chapter 7) The Need for a More General Loop Read marks of students from the keyboard
More informationFundamentals of Computer Programming Using C
CHARUTAR VIDYA MANDAL S SEMCOM Vallabh Vidyanagar Faculty Name: Ami D. Trivedi Class: FYBCA Subject: US01CBCA01 (Fundamentals of Computer Programming Using C) *UNIT 3 (Structured Programming, Library Functions
More informationC++ character set Letters:- A-Z, a-z Digits:- 0 to 9 Special Symbols:- space + - / ( ) [ ] =! = < >, $ # ; :? & White Spaces:- Blank Space, Horizontal
TOKENS C++ character set Letters:- A-Z, a-z Digits:- 0 to 9 Special Symbols:- space + - / ( ) [ ] =! = < >, $ # ; :? & White Spaces:- Blank Space, Horizontal Tab, Vertical tab, Carriage Return. Other Characters:-
More informationControl Statements. If Statement if statement tests a particular condition
Control Statements Control Statements Define the way of flow in which the program statements should take place. Implement decisions and repetitions. There are four types of controls in C: Bi-directional
More informationObject Oriented Pragramming (22316)
Chapter 1 Principles of Object Oriented Programming (14 Marks) Q1. Give Characteristics of object oriented programming? Or Give features of object oriented programming? Ans: 1. Emphasis (focus) is on data
More informationOER on Loops in C Programming
OER on Loops in C Programming Prepared by GROUP ID 537 B. Bala Nagendra Prasad (bbalanagendraprasad@gmail.com C. Naga Swaroopa (swarupabaalu@gmail.com) L. Hari Krishna (lhkmaths@gmail.com) 1 Table of Contents
More informationPrinciples of Computer Science
Principles of Computer Science Lecture 2 Dr. Horia V. Corcalciuc Horia Hulubei National Institute for R&D in Physics and Nuclear Engineering (IFIN-HH) January 27, 2016 Loops: do-while do-while loops do
More informationLECTURE 5 Control Structures Part 2
LECTURE 5 Control Structures Part 2 REPETITION STATEMENTS Repetition statements are called loops, and are used to repeat the same code multiple times in succession. The number of repetitions is based on
More informationC Programming Class I
C Programming Class I Generation of C Language Introduction to C 1. In 1967, Martin Richards developed a language called BCPL (Basic Combined Programming Language) 2. In 1970, Ken Thompson created a language
More informationExamination for the Second Term - Academic Year H Mid-Term. Name of student: ID: Sr. No.
Kingdom of Saudi Arabia Ministry of Higher Education Course Code: ` 011-COMP Course Name: Programming language-1 Deanship of Preparatory Year Jazan University Total Marks: 20 Duration: 60 min Group: Examination
More informationSequence structure. The computer executes java statements one after the other in the order in which they are written. Total = total +grade;
Control Statements Control Statements All programs could be written in terms of only one of three control structures: Sequence Structure Selection Structure Repetition Structure Sequence structure The
More informationLooping. Arizona State University 1
Looping CSE100 Principles of Programming with C++, Fall 2018 (based off Chapter 5 slides by Pearson) Ryan Dougherty Arizona State University http://www.public.asu.edu/~redoughe/ Arizona State University
More informationIT 1033: Fundamentals of Programming Loops
IT 1033: Fundamentals of Programming Loops Budditha Hettige Department of Computer Science Repetitions: Loops A loop is a sequence of instruction s that is continually repeated until a certain condition
More informationAssignment: 1. (Unit-1 Flowchart and Algorithm)
Assignment: 1 (Unit-1 Flowchart and Algorithm) 1. Explain: Flowchart with its symbols. 2. Explain: Types of flowchart with example. 3. Explain: Algorithm with example. 4. Draw a flowchart to find the area
More informationWeek 2. Relational Operators. Block or compound statement. if/else. Branching & Looping. Gaddis: Chapters 4 & 5. CS 5301 Spring 2018.
Week 2 Branching & Looping Gaddis: Chapters 4 & 5 CS 5301 Spring 2018 Jill Seaman 1 Relational Operators l relational operators (result is bool): == Equal to (do not use =)!= Not equal to > Greater than
More informationBRAIN INTERNATIONAL SCHOOL. Term-I Class XI Sub: Computer Science Revision Worksheet
BRAIN INTERNATIONAL SCHOOL Term-I Class XI 2018-19 Sub: Computer Science Revision Worksheet Chapter-1. Computer Overview 1. Which electronic device invention brought revolution in earlier computers? 2.
More informationOVERVIEW OF C. Reads a string until enter key is pressed Outputs a string
1 OVERVIEW OF C 1.1 Input and Output Statements Data input to the computer is processed in accordance with the instructions in a program and the resulting information is presented in the way that is acceptable
More informationModule 4: Decision-making and forming loops
1 Module 4: Decision-making and forming loops 1. Introduction 2. Decision making 2.1. Simple if statement 2.2. The if else Statement 2.3. Nested if Statement 3. The switch case 4. Forming loops 4.1. The
More informationLoops / Repetition Statements. There are three loop constructs in C. Example 2: Grade of several students. Example 1: Fixing Bad Keyboard Input
Loops / Repetition Statements Repetition s allow us to execute a multiple times Often they are referred to as loops C has three kinds of repetition s: the while loop the for loop the do loop The programmer
More informationDecision Making -Branching. Class Incharge: S. Sasirekha
Decision Making -Branching Class Incharge: S. Sasirekha Branching The C language programs presented until now follows a sequential form of execution of statements. Many times it is required to alter the
More informationC library = Header files + Reserved words + main method
DAY 1: What are Libraries and Header files in C. Suppose you need to see an Atlas of a country in your college. What do you need to do? You will first go to the Library of your college and then to the
More informationChapter 1. Principles of Object Oriented Programming
Chapter 1. Principles of Object Oriented Programming Procedure Oriented Programming Vs Object Oriented Programming Procedure Oriented Programming Object Oriented Programming Divided Into In POP, program
More information5. Selection: If and Switch Controls
Computer Science I CS 135 5. Selection: If and Switch Controls René Doursat Department of Computer Science & Engineering University of Nevada, Reno Fall 2005 Computer Science I CS 135 0. Course Presentation
More informationDept. of CSE, IIT KGP
Control Flow: Looping CS10001: Programming & Data Structures Pallab Dasgupta Professor, Dept. of Computer Sc. & Engg., Indian Institute of Technology Kharagpur Types of Repeated Execution Loop: Group of
More informationModule3. Program Control Statements CRITICAL SKILLS. 3.1 Know the complete form of the if statement. 3.2 Use the switch statement
Module3 Program Control Statements CRITICAL SKILLS 3.1 Know the complete form of the if statement 3.2 Use the switch statement 3.3 Know the complete form of the for loop 3.4 Use the while loop 3.5 Use
More informationLoops / Repetition Statements
Loops / Repetition Statements Repetition statements allow us to execute a statement multiple times Often they are referred to as loops C has three kinds of repetition statements: the while loop the for
More informationOperators and Expressions in C & C++ Mahesh Jangid Assistant Professor Manipal University, Jaipur
Operators and Expressions in C & C++ Mahesh Jangid Assistant Professor Manipal University, Jaipur Operators and Expressions 8/24/2012 Dept of CS&E 2 Arithmetic operators Relational operators Logical operators
More informationDecision Making and Loops
Decision Making and Loops Goals of this section Continue looking at decision structures - switch control structures -if-else-if control structures Introduce looping -while loop -do-while loop -simple for
More informationUIC. C Programming Primer. Bharathidasan University
C Programming Primer UIC C Programming Primer Bharathidasan University Contents Getting Started 02 Basic Concepts. 02 Variables, Data types and Constants...03 Control Statements and Loops 05 Expressions
More informationAl-Albayt University Computer Science Department. C++ Programming 1 (901131) Coordinator: Dr. Ashraf Al-Ou n
Al-Albayt University Computer Science Department C++ Programming 1 (901131) Coordinator: Dr. Ashraf Al-Ou n 2019- الفصل الدرا ي س األول 2018 2 Subjects 1. Introduction to C++ Programming 2. Control Structures
More informationBLUE PRINT SUBJECT: - COMPUTER SCIENCE(083) CLASS-XI. Unit Wise Marks
BLUE PRINT SUBJECT: - COMPUTER SCIENCE(083) CLASS-XI Unit Wise Marks Unit No. Unit Name Marks 1. COMPUTER FUNDAMENTAL 10 2. PROGRAMMING METHODOLOGY 12 3. INTRODUCTION TO C++ 1. INTRODUCTION TO C++ 3 TOTAL
More informationLoops (while and for)
Loops (while and for) CSE 1310 Introduction to Computers and Programming Alexandra Stefan 1 Motivation Was there any program we did (class or hw) where you wanted to repeat an action? 2 Motivation Name
More informationb) Give the output of the following program: 6,70,70 2,70 210,282,59290
Set II 1. a) Name the header file for the following built-in functions: i) fabs() math.h ii) isalpha() ctype.h iii) toupper() ctype.h iv) cos() math.h b) Give the output of the following program: 6,70,70
More informationSelection / making decision If statement if-else, if-else-if or nested if Switch Case
SPM 2102 PROGRAMMING LANGUAGE 1 C++ Programming Structure By NORAH MD NOOR 1 Selection / making decision If statement if-else, if-else-if or nested if Switch Case 2 Introduction: Flow of control Normal
More informationDHANALAKSHMI COLLEGE OF ENGINEERING, CHENNAI DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING REWRAP TEST I CS6301 PROGRAMMING DATA STRUCTURES II
DHANALAKSHMI COLLEGE OF ENGINEERING, CHENNAI DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING REWRAP TEST I CS6301 PROGRAMMING DATA STRUCTURES II Year / Semester: III / V Date: 08.7.17 Duration: 45 Mins
More informationCHAPTER-6 GETTING STARTED WITH C++
CHAPTER-6 GETTING STARTED WITH C++ TYPE A : VERY SHORT ANSWER QUESTIONS 1. Who was developer of C++? Ans. The C++ programming language was developed at AT&T Bell Laboratories in the early 1980s by Bjarne
More informationCHAPTER 2.2 CONTROL STRUCTURES (ITERATION) Dr. Shady Yehia Elmashad
CHAPTER 2.2 CONTROL STRUCTURES (ITERATION) Dr. Shady Yehia Elmashad Outline 1. C++ Iterative Constructs 2. The for Repetition Structure 3. Examples Using the for Structure 4. The while Repetition Structure
More informationMAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION (Autonomous) (ISO/IEC Certified) MODEL ANSWER
Important Instructions to examiners: 1) The answers should be examined by key words and not as word-to-word as given in the model answer scheme. 2) The model answer and the answer written by candidate
More informationWhy Is Repetition Needed?
Why Is Repetition Needed? Repetition allows efficient use of variables. It lets you process many values using a small number of variables. For example, to add five numbers: Inefficient way: Declare a variable
More informationFall Semester (081) Dr. El-Sayed El-Alfy Computer Science Department King Fahd University of Petroleum and Minerals
INTERNET PROTOCOLS AND CLIENT-SERVER PROGRAMMING Client SWE344 request Internet response Fall Semester 2008-2009 (081) Server Module 2.1: C# Programming Essentials (Part 1) Dr. El-Sayed El-Alfy Computer
More informationOBJECT ORIENTED PROGRAMMING AND DATA STRUCTURES
Polymorphism: It allows a single name/operator to be associated with different operations depending on the type of data passed to it. An operation may exhibit different behaviors in different instances.
More informationChapter 2. Introduction to C language. Together Towards A Green Environment
Chapter 2 Introduction to C language Aim Aim of this chapter is to provide the fundamentals for basic program construction using C. Objectives To understand the basic information such as keywords, character
More informationCSE 130 Introduction to Programming in C Control Flow Revisited
CSE 130 Introduction to Programming in C Control Flow Revisited Spring 2018 Stony Brook University Instructor: Shebuti Rayana Control Flow Program Control Ø Program begins execution at the main() function.
More information