Lisaveta777

нор

Nov 24th, 2019
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.93 KB | None | 0 0
  1. #include <stdio.h>
  2. int div_count(int);
  3. int ffun();
  4. int dfun();
  5. int wfun();
  6.  
  7.  
  8. int main()
  9. {
  10.     //int i,t_div_count,p_div_count,t_max, p_max,n =1000;//
  11.     //how many dividers: temp - t_div_count, perm - p_div_count
  12.     //max:    temp - t_max     perm - p_max
  13.     //t_div_count = p_div_count = t_max = p_max = 0;
  14.     int fdw;
  15.    
  16.     printf("Chose 1 for using FOR\n2 for using DO\n3 for using WHILE\n");
  17.     scanf("%d",&fdw);
  18.     switch(fdw)
  19.     {
  20.         case 1:ffun();break;
  21.         case 2:dfun();break;
  22.         case 3:wfun();break;
  23.    
  24.     }
  25.    
  26.  
  27.     return 0;
  28. }
  29.  
  30. int dfun()
  31. {
  32.     int i, t_div_count,p_div_count,p_max ,n = 1000;
  33.     p_div_count = p_max = i = 1;
  34.     do
  35.     {
  36.         t_div_count = div_count(i);
  37.         if(t_div_count>p_div_count)
  38.         {
  39.             p_div_count = t_div_count;
  40.             p_max = i;
  41.             printf("p_div_count-%d p_max-%d\t\t",p_div_count,p_max);
  42.        
  43.         }
  44.         i++;
  45.        
  46.     }while(i<n);
  47. }
  48. int wfun()
  49. {
  50.     int i, n, t_div_count,p_div_count,p_max = 0;
  51.     i = 1;
  52.     n=1000;
  53.     while(i<=n)
  54.     {
  55.         t_div_count = div_count(i);
  56.         if(t_div_count>p_div_count)
  57.         {
  58.             p_div_count = t_div_count;
  59.             p_max = i;
  60.             printf("p_div_count-%d p_max-%d\t\t",p_div_count,p_max);
  61.        
  62.         }
  63.       i++;  
  64.     }
  65. }
  66. int ffun()
  67. {
  68.    
  69.     int i, n, t_div_count,p_div_count,p_max = 0;
  70.     n=1000;
  71.     for(i=1;i<=n;i++)
  72.     {
  73.         t_div_count = div_count(i);
  74.         if(t_div_count>p_div_count)
  75.         {
  76.             p_div_count = t_div_count;
  77.             p_max = i;
  78.             printf("p_div_count-%d p_max-%d\t\t",p_div_count,p_max);
  79.        
  80.         }
  81.        
  82.     }
  83. }
  84. int div_count(int number)
  85. {
  86.     int i,div = 1;
  87.     for(i=2;i<=number;i++)
  88.     {
  89.         if(number%i==0)
  90.         {
  91.             div++;
  92.             number/=i;
  93.             i--;
  94.         }
  95.  
  96.     }
  97.     return div;
  98. }
Add Comment
Please, Sign In to add comment