Website Summary Files Commits Branches @commit @diff @stats
path: root / pract_SI / Pract. 04 / Solutions / task14.cpp
diff options
context:
space:
mode:
Commit5b9ce7f4faf1d8d05c42975da9dc903aeecc297c (patch)
Author
 Justsvetoslavov <justsvetoslavov@gmail.com>
2021-11-11 18:32:34 +0200
Committer
 Justsvetoslavov <justsvetoslavov@gmail.com>
2021-11-11 18:32:34 +0200
Filesa0182c23911c751928001687498d9831c1bb1503 /pract_SI/Pract. 04/Solutions/task14.cpp
Introduction_to_programming_FMI-5b9ce7f4faf1d8d05c42975da9dc903aeecc297c.tar
Introduction_to_programming_FMI-5b9ce7f4faf1d8d05c42975da9dc903aeecc297c.tar.gz
Introduction_to_programming_FMI-5b9ce7f4faf1d8d05c42975da9dc903aeecc297c.zip
Parent0b73292819cd7b8bb9460ee817304f6d3295204b (diff)
Edit Order
1 files changed, 0 insertions, 96 deletions
-rw-r--r--pract_SI/Pract. 04/Solutions/task14.cpp96
diff --git a/pract_SI/Pract. 04/Solutions/task14.cpp b/pract_SI/Pract. 04/Solutions/task14.cpp
deleted file mode 100644
index c95c36c..0000000
--- a/pract_SI/Pract. 04/Solutions/task14.cpp
+++ /dev/null
@@ -1,96 +0,0 @@
-#include <iostream>
-#include <cmath>
-
-using namespace std;
-
-//Function to check whether a number is prime
-bool isPrime(int number)
-{
- int size = sqrt(number);
-
-
- for (int i = 2; i <= size; i++)
- {
- if (number % i == 0)
- return false;
- }
-
- return true;
-}
-
-//Print all prime numbers that are smaller than N
-void printAllPrimeToNumber(int number) //Interval [1 ; N]
-{
- std::cout << "1" << ", 2";
-
- for (int i = 3; i <= number; i += 2)
- {
- if (isPrime(i))
- std::cout << ", " << i;
- }
-
- std::cout << "." << std::endl;
-}
-
-//PrimeFactorization
-void PrimeFactor(int number)
-{
- for (int i = 2; i <= number; i++)
- {
- if (isPrime(i) && number % i == 0)
- {
- if (i == number) //last step, no space
- std::cout << i;
- else
- std::cout << i << " ";
-
- number /= i;
- i--;
- }
- }
- std::cout << std::endl;
-}
-
-//Function whether the number N can be expressed as a sum of two prime numbers
-bool checkSumOfTwoPrimes(int number,int &primeOfNumber)
-{
- int size = number / 2; //36 = 7 + 29, 16 = 3 + 13 , 36 = 5 + 31
- for (int i = 2;i <= size; i++)
- {
- //16 = 3 + x , x = 16 - 3 , x = 13 PRIME
- if (isPrime(i) && isPrime(number - i))
- {
- primeOfNumber = i;
- return true;
- }
- }
- return false;
-}
-
-int main()
-{
- int number;
- std::cin >> number;
-
- if (isPrime(number))
- std::cout << number << " is prime!" << std::endl;
- else
- std::cout << number << " is composite number!" << std::endl;
-
- std::cout << std::endl << "Prime numbers up to " << number << " are: ";
- printAllPrimeToNumber(number);
-
- std::cout << "Factoring of: " << number << " is: ";
- PrimeFactor(number);
-
- int primeOfNumber;
- if (checkSumOfTwoPrimes(number, primeOfNumber))
- std::cout << primeOfNumber << " + " << number - primeOfNumber << std::endl;
- else
- std::cout << "Error!" << std::endl;
-
-
-
-
- return 0;
-}