Advertisement
lineoff

Armstrong

Dec 30th, 2016
240
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.51 KB | None | 0 0
  1. //
  2. //  main.c
  3. //  Armstrong
  4. //
  5. //  Created by Abdelali on 10/05/2016.
  6. //  Copyright © 2016 Abdelaali. All rights reserved.
  7. //
  8.  
  9. #include <stdio.h>
  10.  
  11. int pow3(int x){
  12.     return x*x*x;
  13. }
  14.  
  15.  
  16. int armstrong (int x){
  17.     int c = x;
  18.     int s = 0;
  19.     while (c!=0) {
  20.         s += pow3(c%10);
  21.         c/=10;
  22.     }
  23.     if(x == s)
  24.         return 1;
  25.     return -1;
  26. }
  27.  
  28.  
  29. int main(int argc, const char * argv[]) {
  30.     if(armstrong(153)) printf("amrstrong");
  31.     else printf("ne pas");
  32.     return 0;
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement