Created
December 11, 2012 00:46
-
-
Save pagenoare/4254733 to your computer and use it in GitHub Desktop.
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 characters
#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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment