Advertisement
Guest User

Untitled

a guest
Oct 27th, 2013
315
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.64 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. #define n 8
  5.  
  6. int main () {
  7.  
  8. unsigned int zahl, temp; /*aktuelle Zahl und Hilfsvariable*/
  9. double summe;
  10. int a [n] = {0}; /*Die aktuelle Ziffern zu speichern*/
  11. int ziffern; /*Zahle der Ziffern*/
  12. int i, idx; /*Laufvarieblen*/
  13.  
  14. printf("Die max. achtzifferige Armstrong-Zahlen sind:\n\n");
  15.  
  16. for (zahl=1; zahl < 99999999; zahl++)   {
  17.     temp = zahl;
  18.     summe = 0;
  19.     i=0; ziffern=0;
  20.     while (temp)    {
  21.         a[i]= temp%10;
  22.         i++;
  23.         temp /= 10;
  24.         ziffern++;
  25.     }
  26.         for (idx=0; a[idx]>0; idx++)    {
  27.             summe += pow((double) a[idx], (double) ziffern);}
  28.         if (summe == zahl)
  29.             printf("%lf\n", zahl);
  30. }
  31.  
  32. return 0;}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement