08
30
2007
Pętle for i while
Napisał Michał w kategorii Cpp, Studia, tags: Cpp, pętle, programowaniePolecenie:
Testujemy dwie pętle while oraz for:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | #pragma hdrstop #pragma argsused #include <iostream .h> #include <stdio .h> main() { int i,min,max; cout< <"Sprawdzamy Min i Max"<<endl; cout<<endl<<endl; cout<<"Testujemy dwie petle while oraz for: "<<endl; do { cout<<"Podaj min: "; cin>>min; cout< <"Podaj max: "; cin>>max; if(min>max) cout< <"\n\tBlad! Min musi byc < od Max!\n"<<endl; }while(min>max) cout< <"Podales min: "<<min<<", max: "<<max<<endl; cout<<"Wyswietl co 2 od min do max:"<<endl<<endl; cout<<"Wyswietl za pomoca petli for:"<<endl; for(i=min;i<=max;i=i+2) cout<<i<<endl; cout<<endl<<"Wyswietl za pomoca petli while:"<<endl; while(min<=max) { cout<<min<<endl; min=min+2; } system("PAUSE"); } |


Wpisy (RSS)