Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <ctime>
- #include <cstdlib>
- #include <cmath>
- using namespace std;
- bool pierwsze(int num) {
- if (num <= 1) return false;
- for (int i = 2; i <= sqrt(num); i++) {
- if (num % i == 0) return false;
- }
- return true;
- }
- int main() {
- int tab[50];
- int count = 0;
- int min_pierwsze = INT_MAX;
- int max_pierwsze = INT_MIN;
- int first_digit, last_digit;
- srand(time(0));
- for (int i = 0; i < 50; i++) {
- tab[i] = rand() % 401 + 100;
- }
- cout << "Liczby pierwsze w tablicy:" << endl;
- for (int i = 0; i < 50; i++) {
- if (pierwsze(tab[i])) {
- cout << tab[i] << " ";
- count++;
- if (tab[i] < min_pierwsze) min_pierwsze = tab[i];
- if (tab[i] > max_pierwsze) max_pierwsze = tab[i];
- }
- }
- cout << endl << "Ilosc liczb pierwszych w tablicy: " << count << endl;
- cout << "Najmniejsza liczba pierwsza w tablicy: " << min_pierwsze << endl;
- cout << "Najwieksza liczba pierwsza w tablicy: " << max_pierwsze << endl;
- cout << endl << "Liczby, w ktorych pierwsza i ostatnia cyfra sa takie same:" << endl;
- int max_num=0;
- for (int i = 0; i < 50; i++) {
- first_digit = tab[i] / 100;
- last_digit = tab[i] % 10;
- if (first_digit == last_digit)
- {
- cout << tab[i] << " ";
- if(max_num == 0 || max_num < tab[i]) max_num = tab[i];
- }
- }
- cout << endl << "maksymalna liczba z pierwszych i ostatnich takich samych: " << max_num << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement