Advertisement
Guest User

Untitled

a guest
May 20th, 2018
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. #include<stdio.h>
  2. #include <math.h>
  3. int a,b;
  4. int Armstrong(long long n)
  5. {
  6. long long t, scs=0, cs=0;
  7. long long m=n;
  8. long long b=n;
  9. while(n>0)
  10. {
  11. n/=10;
  12. scs++;
  13. }
  14. while(m>0)
  15. {
  16. t=m%10;
  17. cs+=pow(t, scs);
  18. m/=10;
  19. }
  20. if(cs==b) return 1;
  21. else return 0;
  22. }
  23. int main()
  24. {
  25. long long a, b, kt = 0;
  26. scanf("%d %d",&a, &b);
  27. if(a<b)
  28. {
  29. for(int i=a; i <=b ; i++)
  30. {
  31. if(Armstrong(i))
  32. {
  33. printf("%d ", i);
  34. kt = 1;
  35. }
  36. }
  37. }
  38. else
  39. {
  40. for(int i=b; i <=a ; i++)
  41. {
  42. if(Armstrong(i))
  43. {
  44. printf("%d ", i);
  45. kt = 1;
  46. }
  47. }
  48. }
  49. if (kt == 0) printf("0");
  50.  
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement