Advertisement
rdsedmundo

cfatores temp.c

Jan 8th, 2014
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.31 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. int int_length(int number) {
  5.     char _chstring[16];
  6.     sprintf(_chstring, "%d", number);
  7.  
  8.     return strlen(_chstring);
  9. }
  10.  
  11. int i_pow(int num, int tobase) {
  12.     int i_result = 1, i;
  13.     for(i = 0; i < tobase; i++)
  14.         i_result *= num;
  15.  
  16.     return i_result;
  17. }
  18.  
  19. int isprimo(int number) {
  20.     int ndiv = 0, i;
  21.  
  22.     for(i = number; i > 0; i--) {
  23.         if(number%i == 0)
  24.             ndiv++;
  25.     }
  26.  
  27.     if(ndiv == 2)
  28.         return 1;
  29.  
  30.     return 0;
  31. }
  32.  
  33. int main(void) {
  34.     int num;
  35.  
  36.     while(1) {
  37.         scanf("%d", &num);
  38.  
  39.         if(!num)
  40.             break;
  41.  
  42.         int count = 0;
  43.  
  44.         if(isprimo(num))
  45.             count++;
  46.  
  47.         int i, j;
  48.  
  49.         for(i = int_length(num); i > 0; i--) {
  50.             int _temp_num = num % (i_pow(10, i));
  51.             printf("\n");
  52.             printf("temp [i=%d]: %d\n", i, _temp_num);
  53.  
  54.             if(isprimo(_temp_num))
  55.                 count++;
  56.  
  57.             for(j = 1; j <= int_length(_temp_num); j++) {
  58.                 int _other_num = _temp_num % (i_pow(10, j));
  59.  
  60.                 printf("other [j=%d]: %d\n", j, _other_num);
  61.  
  62.                 if(isprimo(_other_num))
  63.                     count++;
  64.             }
  65.         }
  66.  
  67.         printf("%d : %d\n", num, count);
  68.     }
  69.  
  70.     return 0;
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement