Advertisement
Guest User

Untitled

a guest
Dec 8th, 2012
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. int potencija(int x)
  5. {
  6. int k;
  7. for(k=1; ; k++)
  8. {
  9. if((long)pow(2, k)==x ||(long)pow(3, k)==x) return 1;
  10.  
  11. if((long)pow(2, k)>x && (long)pow(3, k)>x) break;
  12. }
  13. return 0;
  14. }
  15.  
  16. int main(void)
  17. {
  18. int x, brojac=0, i, x_max;
  19.  
  20. scanf("%d", &x);
  21. if(x==0)
  22. {
  23. printf("Prazan niz!\n");
  24. return 0;
  25. }
  26.  
  27. for(i=1; ; i++)
  28. {
  29. if(potencija(x))
  30. {
  31. brojac++;
  32. if(brojac==1 || x>x_max) x_max=x; /*brojac==1 znaci:kad nadje prvi takav broj onda ga postavi na max*/
  33.  
  34. }
  35.  
  36. scanf("%d", &x);
  37. if(x==0) break;
  38. }
  39. if(brojac==0) printf("Nema takvih brojeva u nizu.\n");
  40. else
  41. {
  42. printf("ukupno=%d\n", brojac);
  43. printf("%d\n", x_max);
  44. }
  45. return 0;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement