factorization
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | #include <stdio.h> #define BOX_SIZE 10 int Is_Prime(int Natural_Number); int factorization(int factor, int Prime_Factor); int main(void) { int Array_Prime_Factor_Box[BOX_SIZE] = { 0, }; int Prime_Factor = 2; float factor = 36.f; int remainder = 0; int index = 0; for (index = 0; index < BOX_SIZE; index++) { if (Is_Prime(Prime_Factor)) { int temporary = factorization(factor, Prime_Factor); if (temporary == 0) { Array_Prime_Factor_Box[index] = Prime_Factor; factor /= Prime_Factor; } else if (temporary > 0) { Prime_Factor++; index--; } else break; remainder++; } else { Prime_Factor++; index--; } } if (factor != 1) Array_Prime_Factor_Box[remainder - 1 - 1] = (int)factor; for (index = 0; Array_Prime_Factor_Box[index] != 0; index++) { printf("%d\t", Array_Prime_Factor_Box[index]); } return 0; } int factorization(int factor, int Prime_Factor) { if (factor < Prime_Factor) return -1; if ((factor / Prime_Factor) == 0) return -2; return factor % Prime_Factor; } int Is_Prime(int Natural_Number) { if (Natural_Number < 2) return -1; int Prime_Check = 0; for (Prime_Check = 2; Prime_Check < Natural_Number; Prime_Check++) { if (Natural_Number % Prime_Check == 0) return 0; } return Natural_Number; } | cs |
0 개의 댓글:
댓글 쓰기