SHARE
TWEET

Untitled

a guest Feb 18th, 2020 61 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <stdbool.h>
  3. #include <math.h>
  4.  
  5.  
  6.  
  7. int factorcalc(int num, int div) {
  8.     return (num/div);  
  9. }
  10.  
  11. int factorresto(int num, int div) {
  12.     return (num%div);
  13. }
  14.  
  15.  
  16.  
  17. bool isPrime(int num) {
  18.     int i, flag = 1;
  19.     for (i = 2; i <= sqrt(num); i++) {
  20.         if (num % i == 0) {
  21.             flag = 0;
  22.             break;
  23.         }
  24.     }
  25.  
  26.     if (flag == 1) {
  27.         return true;
  28.     }
  29.     else {
  30.         return false;
  31.     }
  32.  
  33.     return 0;
  34. }
  35.  
  36. int factor(int num, int array[]) {
  37.     int savefactor[500];
  38.     int e = 0;
  39.     for (int t=0; t<500; t++) {
  40.         while ((!isPrime(num)) && (factorresto(num, array[t]) == 0 )) {
  41.             num = factorcalc(num, array[t]);
  42.             savefactor[e] = array[t];
  43.             printf("%d\n", savefactor[e]);
  44.             e++;   
  45.         }
  46.     }
  47.     e++;
  48.     if (num == 0) {
  49.         e--;
  50.         printf("Resultado-> %d", e);
  51.     }else {
  52.         printf("Resultado-> %d", e);
  53.     }
  54.     return 0;
  55.    
  56. }
  57.  
  58. int main() {
  59.     int array[500];
  60.     int countarray = 0;
  61.    
  62.     for (int u=2; u<500; u++) {
  63.         if (isPrime(u)) {
  64.             array[countarray] = u;
  65.             countarray++;
  66.         }
  67.     }
  68.  
  69.  
  70.     factor(83265913, array);
  71.    
  72. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top