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 is_prime(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 array[50];
- int count = 0;
- int min_prime = INT_MAX;
- int max_prime = INT_MIN;
- int first_digit, last_digit;
- srand(time(0));
- for (int i = 0; i < 50; i++) {
- array[i] = rand() % 401 + 100;
- }
- cout << "Liczby pierwsze w tablicy:" << endl;
- for (int i = 0; i < 50; i++) {
- if (is_prime(array[i])) {
- cout << array[i] << " ";
- count++;
- if (array[i] < min_prime) min_prime = array[i];
- if (array[i] > max_prime) max_prime = array[i];
- }
- }
- cout << endl << "Ilosc liczb pierwszych w tablicy: " << count << endl;
- cout << "Najmniejsza liczba pierwsza w tablicy: " << min_prime << endl;
- cout << "Najwieksza liczba pierwsza w tablicy: " << max_prime << 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 = array[i] / 100;
- last_digit = array[i] % 10;
- if (first_digit == last_digit)
- {
- cout << array[i] << " ";
- if(max_num == 0 || max_num < array[i]) max_num = array[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