Created
December 11, 2012 00:46
Revisions
-
pagenoare revised this gist
Dec 11, 2012 . 1 changed file with 7 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -20,16 +20,21 @@ int sum(int tab[]) return n; } int max_min(int tab[], bool is_max=true) { int max = tab[0], min = tab[0]; for(int i = 0; i <= N; i++) { if(max < tab[i]) { max = tab[i]; } if(min > tab[i]) { min = tab[i]; } } return is_max ? max : min; } -
pagenoare created this gist
Dec 11, 2012 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,114 @@ #include <iostream> #include <cstdlib> #define N 100 using namespace std; void wypelnij(int tab[]) { for(int i = 0; i <= N; i++) { tab[i] = rand(); } } int sum(int tab[]) { int n = 0; for(int i = 0; i <= N; i++) n += tab[i]; return n; } int max_min(int tab[], bool is_max=true) { int max = tab[0], min = tab[0]; for(int i = 0; i <= N; i++) if(max < tab[i]) max = tab[i]; if(min > tab[i]) min = tab[i]; return is_max ? max : min; } int count_0(int tab[]) { int n = 0; for(int i = 0; i <= N; i++) if(tab[i] == 0) n++; return n; } bool is_symetric(int tab[]) { int j = 0; for(int i = 0; i <= N / 2; i++) if(tab[i] == tab[N-1-i]) j++; return j == (N / 2) + 1 ? true : false; } bool ros(int tab[]) { int l = 0; for(int i = 0; i <= N; i++) if(tab[i] < tab[i+1]) l++; return l == N ? true : false; } int main() { int tab[N]; int act; while(1) { cout << "=== MENU ===" << endl; cout << "1. Wypelnienie. " << endl; cout << "2. Sumowanie. " << endl; cout << "3. Max i min. " << endl; cout << "4. Ilosc zer. " << endl; cout << "5. Sprawdz, czy tablica jest symetryczna. " << endl; cout << "6. Sprawdz, czy tablica jest posortowana rosnaco. " << endl; cin >> act; switch(act) { case 1: wypelnij(tab); for(int i = 0; i <= N; i++) { cout << tab[i] << endl; } break; case 2: cout << sum(tab) << endl; break; case 3: cout << "MAX: " << max_min(tab) << endl << "MIN: " << max_min(tab, false) << endl; break; case 4: cout << "Ilosc 0: " << count_0(tab) << endl; break; case 5: is_symetric(tab) ? cout << "symetryczna" : cout << "niesymetryczna"; cout << endl; break; case 6: ros(tab) ? cout << "posortowana" : cout << "nieposortowana"; cout << endl; break; default: cout << "Wybierz akcje!" << endl; } } return 0; }