Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <math.h>
- #define n 8
- int main () {
- unsigned int zahl, temp; /*aktuelle Zahl und Hilfsvariable*/
- double summe;
- int a [n] = {0}; /*Die aktuelle Ziffern zu speichern*/
- int ziffern; /*Zahle der Ziffern*/
- int i, idx; /*Laufvarieblen*/
- printf("Die max. achtzifferige Armstrong-Zahlen sind:\n\n");
- for (zahl=1; zahl < 99999999; zahl++) {
- temp = zahl;
- summe = 0;
- i=0; ziffern=0;
- while (temp) {
- a[i]= temp%10;
- i++;
- temp /= 10;
- ziffern++;
- }
- for (idx=0; a[idx]>0; idx++) {
- summe += pow((double) a[idx], (double) ziffern);}
- if (summe == zahl)
- printf("%lf\n", zahl);
- }
- return 0;}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement