Advertisement
Guest User

Persistencia

a guest
Aug 16th, 2013
1,011
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.53 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int persistence(int num);
  4. int main() {
  5.     int val = 0;
  6.     while(val<20){
  7.         printf("%d\n",minPersistence(val));
  8.         val++;
  9.     }
  10.     getche();
  11. }
  12.  
  13. int persistence(int num) {
  14.     int counter=0;
  15.     if(num<10) return 0;
  16.     do {
  17.         char str[20000];
  18.         sprintf(str, "%d", num);
  19.         num= str[0]-'0';
  20.         int i=1;
  21.         while (str[i] != '\0') {
  22.             num*= str[i]-'0';
  23.             i++;
  24.         }
  25.         counter++;
  26.     }while(num>9);
  27.     return counter;
  28. }
  29.  
  30. int minPersistence(int num){
  31.     int val=0;
  32.     while(persistence(val)!=num){
  33.         val++;
  34.     }
  35.     return val;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement