Initial commit
This commit is contained in:
48
PI/Ćwiczenia/20221024115005.md
Normal file
48
PI/Ćwiczenia/20221024115005.md
Normal file
@@ -0,0 +1,48 @@
|
||||
## Jak policzyć słowa w książce?
|
||||
```cpp
|
||||
const int rozmiar_książki = 300;
|
||||
int liczba_słów_na_stronie[rozmiar_książki];
|
||||
liczba_słów_na_stronie[2]=20; // <-- 20 słów na stronie 3
|
||||
int suma = liczba_słów_na_stronie[0];
|
||||
for (int nr = 1;nr<rozmiar;nr++){
|
||||
suma+=liczba_słów_na_stronie[nr];
|
||||
}
|
||||
```
|
||||
![[Drawing 2022-10-24 12.04.19.excalidraw]]
|
||||
|
||||
## Funkcja wyliczająca minimum i maksimum
|
||||
|
||||
```CpP
|
||||
void minmax1(double a[],int &min, int &max){
|
||||
max = 0;
|
||||
for (int i = 1; i<n;i++)
|
||||
if (a[i]>a[max]){
|
||||
max = i;
|
||||
}
|
||||
min = 0;
|
||||
for (int i = 1; i<n;i++)
|
||||
if (a[i]<a[max]){
|
||||
min = i;
|
||||
}
|
||||
} //2(n-1)
|
||||
void minmax2(double a[],int &min, int &max){
|
||||
max = min = 0;
|
||||
for (int i = 1; i<n;i++)
|
||||
if (a[i]>a[max]){
|
||||
max = i;
|
||||
};
|
||||
if (a[i]<a[max]){
|
||||
min = i;
|
||||
};
|
||||
} //2(n-1)
|
||||
void minmax3(double a[],int &min, int &max){
|
||||
max = min = 0;
|
||||
for (int i = 1; i<n;i++)
|
||||
if (a[i]>a[max]){
|
||||
max = i;
|
||||
} else if (a[i]<a[max]){
|
||||
min = i;
|
||||
};
|
||||
} // opt n-1 where 1/n!; pes 2(n-1) where 1/n; avg 2(n-1)-ln(n)-C
|
||||
|
||||
```
|
||||
Reference in New Issue
Block a user