Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "pch.h" //biblioteka visual studio
- #include <stdlib.h>
- #include <stdio.h>
- int main()
- {
- int ilosc, min, max, indeksmin=0, indeksmax=0;
- int *liczby;
- printf("Podaj liczbe elementow: ");
- scanf_s("%d", &ilosc);
- liczby = (int*)malloc(ilosc);
- for (int i = 0; i < ilosc; i++)
- {
- printf("Podaj element numer %d: ", i+1);
- scanf_s("%d", &liczby[i]);
- }
- printf("\nIndeks Liczba\n");
- for (int i = 0; i < ilosc; i++)
- {
- printf("%d %d\n", i + 1, liczby[i]);
- }
- min = liczby[0];
- for (int i = 0; i < ilosc; i++)
- {
- if (min > liczby[i])
- {
- min = liczby[i];
- indeksmin = i;
- }
- }
- max = liczby[0];
- for (int i = 0; i < ilosc; i++)
- {
- if (max < liczby[i])
- {
- max = liczby[i];
- indeksmax = i;
- }
- }
- printf("\nNajmniejszy element: %d na miejscu: %d", min, indeksmin+1);
- printf("\nNajwiekszy element: %d na miejscu %d", max, indeksmax+1);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement