Presentation is loading. Please wait.

Presentation is loading. Please wait.

Unazat while.

Similar presentations


Presentation on theme: "Unazat while."— Presentation transcript:

1 Unazat while

2 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

3 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

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

5 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

6 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

7 Unazat do-while

8 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

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

10 // 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

11 //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


Download ppt "Unazat while."

Similar presentations


Ads by Google