Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Zadanie 4. Napisac program znajdujacy wartosc maksymalna i minimalna w tablicy
- z zadania 1, a nastepnie wyswietlic te warto±ci i ich pozycje w tablicy.
- */
- #include <stdio.h>
- int main(int argc, char **argv) {
- int size, tab[30];
- printf("ile liczb chcesz podac?\n"); //wyswietlenie komunikatu
- scanf("%d", &size); //wprowadzenie zmiennych
- if(size<1 || size>30) {
- printf("podana ilosc powinna znajdowac sie w zakresie od 1 do 30!\n");
- return 1;
- }
- printf("podaj %d liczb calkowitych:\n", size);
- for(int x = 0; x<size; x++) scanf("%d", &tab[x]);
- int nw = -1, nwid = -1, nm = -1, nmid = -1;
- for(int x = 0; x<size; x++) {
- if(nw<tab[x]) {
- nw = tab[x];
- nwid = x;
- }
- if(nm==-1||nm>tab[x]) {
- nm = tab[x];
- nmid = x;
- }
- }
- printf("najwieksza liczba w tablicy to %d o pozycji %d\nnajmniejsza liczba w tablicy to %d o pozycji %d\n", nw, nwid, nm, nmid);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement