Advertisement
Mizuhara_Chizuru

Untitled

Jun 2nd, 2021
63
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*Code by Surya a.k.a Sunny*/
  2. /* by https://www.codechef.com/users/spsc */
  3. #include <bits/stdc++.h>
  4. #define lli long long
  5. #define pi 3.14159265358979323846
  6. #define MOD 1000000007
  7. #define foi(n) for(lli i=0;i<n;i++)
  8. #define foj(n) for(lli j=0;j<n;j++)
  9. #define test(T) lli T;cin>>T;while(T--)
  10. #define loop(i, a, b) for(int i = (a); i<= (b); i++)
  11. using namespace std;
  12. int main()
  13. {
  14. ios_base::sync_with_stdio(false);
  15. cin.tie(NULL);
  16. // WAP to check for Armstrong Number
  17. int a,temp,i=0,ans=0,digit=0,power;
  18. scanf("%d",&a);
  19. temp=a;
  20. while(a)
  21. {
  22. i++;
  23. a/=10;
  24. }
  25. a=temp;
  26. for(int j=1;j<=i;j++)
  27. {
  28. digit=a%10;
  29. power=pow(digit,i);
  30. //cout<<power<<'\n';
  31. ans+=power;
  32. /*power=1;
  33. for(int a=1;a<=i;a++)
  34. power*=digit;
  35. ans+=power;
  36. */
  37. a/=10;
  38. }
  39. //cout<<ans;
  40. if(!(ans-temp))
  41. printf("This is an Armstrong number\n");
  42. else
  43. printf("This is not an Armstrong number\n");
  44. }
  45.  
Advertisement
RAW Paste Data Copied
Advertisement