Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- This program finds if I like a number or not.
- As a rule, I only like multiples of 2, 6, or 10.
- There might be exceptions like 76, but that's rare.
- Please note: I only really know Python, so this code might be rough
- */
- #include <stdio.h>
- #include <stdbool.h>
- bool isPrime(int num) {
- // If a number is even, but not 2, return false
- if (num == 2) {
- return true;
- }
- if (num <= 1 || num % 2 == 0) {
- return false;
- }
- // Check every odd factor of a number, since we already got rid of all the even numbers
- for (int i = 3; i < num/2; i += 2) {
- if (num % i == 0) {
- return false;
- }
- }
- return true;
- }
- bool isGood(int num) {
- // Upon second thought, I kinda like 76 but that's the only exception
- if (num == 76) {
- return true;
- }
- // Get rid of 54 manually
- if (num == 54) {
- return false;
- }
- if (num % 2 == 0) {
- // Get rid of even numbers with prime factors other than 3 and 5
- for (int i = 2; i < num; i++) {
- if (isPrime(i) && i != 2 && i != 3 && i != 5 && num % i == 0) {
- return false;
- }
- }
- } else {
- return false; // Get rid of all odd numbers
- }
- return true;
- }
- int main() {
- int number;
- printf("Enter a number: ");
- scanf("%d", &number);
- if (isGood(number)) {
- printf("%d is acceptable\n", number);
- } else {
- printf("%d is NOT acceptable\n", number);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment