Florii11

Untitled

Jan 27th, 2021 (edited)
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.93 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int intreg(double x)
  5. {
  6.     int y = (int)x;
  7.     return (x == y);
  8. }
  9.  
  10. int cate_cifre(long long x)
  11. {
  12.     int ct=0;
  13.     while(x)
  14.     {
  15.         x/=10;
  16.         ct++;
  17.     }
  18.     return ct;
  19. }
  20.  
  21. int main()
  22. {
  23.     double x;
  24.     scanf("%lf",&x);
  25.     int ctmax=0;
  26.     double max;
  27.     int ok=1;
  28.     while(x && ok)
  29.     {
  30.         double y=x;
  31.         int ct=0;
  32.         if(intreg(x))
  33.         {
  34.             ok=0;
  35.             break;
  36.         }
  37.         while(!intreg(y) && cate_cifre(y)<15)
  38.         {
  39.             y=y*10;
  40.             ct++;
  41.         }
  42.         long long z=y;
  43.         while(z%10==0)
  44.         {
  45.             z/=10;
  46.             ct--;
  47.         }
  48.         if(ct>=ctmax)
  49.         {
  50.             ctmax=ct;
  51.             max=x;
  52.         }
  53.         scanf("%lf",&x);
  54.     }
  55.     if(ok==1)
  56.         printf("%lf",max);
  57.     else
  58.         printf("Date de intrare invalide");
  59.     return 0;
  60. }
  61.  
Add Comment
Please, Sign In to add comment