Unazat while.

Slides:



Advertisements
Similar presentations
While Loops Programming. COMP102 Prog Fundamentals I: while Loops/Slide 2 Shortcut Assignments l C++ has a set of shortcut operators for applying an operation.
Advertisements

True or false A variable of type char can hold the value 301. ( F )
Multiple-Subscripted Array
What is the out put #include using namespace std; void main() { int i; for(i=1;i
Loops Programming. COMP104 Lecture 9 / Slide 2 Shortcut Assignment l C++ has a set of operators for applying an operation to a variable and then storing.
VARIABLES, TYPES, INPUT/OUTPUT, ASSIGNMENT OPERATION Shieu-Hong Lin MATH/CS Department Chapel.
C++ Tutorial Hany Samuel and Douglas Wilhelm Harder Department of Electrical and Computer Engineering University of Waterloo Copyright © 2006 by Douglas.
Current Assignments Homework 3 is due tonight. Iteration and basic functions. Exam 1 on Monday.
While Loops Programming. COMP102 Prog Fundamentals I: while Loops/Slide 2 Shortcut Assignments l C++ has a set of shortcut operators for applying an operation.
CSC1201: Programming Language 2 Lecture 1 Level 2 Course Nouf Aljaffan (C) CSC 1201 Course at KSU1.
COMP102 – Programming Fundamentals I LA2B (Mon 5-7pm) LA2E (Fri 3-5pm) LA2F (Fri 5-7pm) TA: Jackie Lo.
1 For Loops l From Chapter 9 l A shorthand way of coding count loops.
April 11, 2005 More about Functions. 1.Is the following a function call or a function header? calcTotal(); 2.Is the following a function call or a function.
Chapter 05 (Part II) Control Statements: Part II.
Chapter 2 Creating a C++ Program. Elements of a C++ Program Four basic ways of structuring a program Four basic ways of structuring a program 1.Sequencing.
Current Assignments Project 3 has been posted, due next Tuesday. Write a contact manager. Homework 6 will be posted this afternoon and will be due Friday.
Intro. to Computer Programming Eng. Nehal A. Mohamed Spring Semester-2016.
Chapter five exercises. a. false; b. true; c. false; d. true; e. true; f. true; g. true; h. false.
LESSON 5 Loop Control Structure. Loop Control Structure  Operation made over and over again.  Iterate statement.
Looping I (while statement). CSCE 1062 Outline  Looping/repetition construct  while statement (section 5.1)
1 C++ Classes and Data Structures Course link…..
Example 21 #include<iostream.h> int main() { char Letter = 0;
Chapter 13 Introduction to C++ Language
Introduction to C++ (Extensions to C)
LESSON 2 Basic of C++.
Intro to Programming Week # 6 Repetition Structure Lecture # 10
Chapter 3 L7.
Command Line Arguments
Sorting Algorithms.
Programming Fundamentals
Control Structures Combine individual statements into a single logical unit with one entry point and one exit point. Used to regulate the flow of execution.
לולאות קרן כליף.
Reserved Words.
Andy Wang Object Oriented Programming in C++ COP 3330
Function Basics.
Control Structures Combine individual statements into a single logical unit with one entry point and one exit point. Used to regulate the flow of execution.
Programming -2 برمجة -2 المحاضرة-5 Lecture-5.
Random Number Generation
Elementet e gjuhës C++.
Të llogaritet shuma e elementeve të vektorit.
Elementet e gjuhës C++.
Basic Input and Output C++ programs can read and write information using streams A simple input stream accepts typed data from a keyboard A simple output.
אבני היסוד של תוכנית ב- C++
אבני היסוד של תוכנית ב- C++
Screen output // Definition and use of variables
5. Unazat.
הרצאה 03 אבני היסוד של תוכנית ב- C
6. Unaza While dhe Do While
F U N K S I O N E T.
Starting Out with C++: From Control Structures through Objects
Pointers & Functions.
اصول کامپیوتر ۱ مبانی کامپیوتر و برنامه‌سازی
Code::Block vs Visual C++
Summary Two basic concepts: variables and assignments Basic types:
Degëzimet.
Control Structures Part 2
Programim I Degëzimet Gazmend Xhaferi.
Variablat dhe konstantet
Degëzimet.
Let’s all Repeat Together
Statements and flow control
Reading from and Writing to Files
Pointers & Functions.
(Dreaded) Quiz 2 Next Monday.
Unazat FOR.
Programming Fundamental
Introduction to Algorithms and Programming COMP151
Operatorët.
Reading from and Writing to Files
CSE Module 1 A Programming Primer
Presentation transcript:

Unazat while

Unazat Strukturat kontrolluese, përmes së cilave përsëriten pjesë të programeve, quhen unaza (ang. loop) Për realizimin e unazave në gjuhën C++ shfrytëzohe komanda for, while dhe do-while 12:13

Unazat while i=f; while (i<=p) { a; i=i+h; } Unazat të cilat realizohen duke e shfrytëzuar komandën while, ngjashëm si edhe ato që realizohen me komandën for, shkurt njihen si unaza while Forma e përgjithshme e unazës while: i=f; while (i<=p) { a; i=i+h; } i=f; while (i<=p) { a; i=i+h; } 12:13

Bllok-diagrami i=f i<=p false true a i=i+h 12:13

Shembull // F = (n+1)! #include <iostream> using namespace std; int main() { double F=1; int i,n; cout << "\nVlera e variables n: "; cin>> n; i=1; while (i<=n+1) F=F*i; i=i+1; } cout << "\nVlera e faktorielit F= " << F << "\n\n"; return 0; false

Shembull 2 // Tabela e katroreve te numrave cift #include <iomanip> #include <iostream> using namespace std; int main() { int i,m; char T[] = "-------------------------"; cout << "\nVlera kufitare m: "; cin>> m; cout<<"\n Numri Katrori \n" << T <<endl; i=2; while (i<=m) { cout << setw(7) << i << setw(10) << i*i << endl; i=i+2; } cout << T << "\n\n"; return 0; false

Unazat do-while

Unazat do-while i=f; do { a; i=i+h; } while (i<=p) Përveç me komandat for dhe while, unazat mund të realizohen edhe duke i shfrytëzuar komanda do e while Forma e përgjithshme e unazës do-while: i=f; do { a; i=i+h; } while (i<=p) i=f; while (i<=p) { a; i=i+h; } 12:13

Bllok-diagrami i=f a i=i+h true i<=p false 12:13

// llogaritja e katroreve te numrave tek dhe kubeve te numrave cift #include <math.h> #include <iostream> using namespace std; int main() { double i,m; double s=0; cout << "\nVlera e variables m: "; cin>> m; i=1; do {s=s + pow(i,2); i=i+2; } while (i<=m); i=2; {s=s + pow(i,3); cout << "Shuma e kerkuar eshte s= " << s << "\n\n"; return 0; Shembull false

//Shuma e anetareve te matrices se dhene R(m,n) #include <iostream> using namespace std; int main() { const int m=4, n=3; int i,j; int R[m][n] = { {4,7,2}, {5,9,3}, {6,1,12}, {8,15,4} }; float s=0; i=0; do { j=0; { s=s+R[i][j]; j++; } while (j<n); i++; while (i<m); cout << " Shuma e llogaritur s= " <<s << "\n\n"; return 0; Shembull 2 false