Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #include <math.h>
- int eh_numero_de_armstrong(int n);
- int intpow(int base, int exp);
- int main()
- {
- int x;
- printf("Digite um numero qualquer: ");
- scanf("%d", &x);
- if (eh_numero_de_armstrong(x))
- printf("%d eh um numero de Armstrong.\n", x);
- else
- printf("%d nao eh um numero de Armstrong.\n", x);
- return 0;
- }
- int eh_numero_de_armstrong(int n)
- {
- char str[100];
- int soma_alg = 0;
- sprintf(str, "%d", n);
- for (int i = 0; i < strlen(str); i++)
- soma_alg += intpow(str[i] - '0', strlen(str));
- if (n == soma_alg)
- return 1;
- else
- return 0;
- }
- int intpow(int base, int exp) {
- int result=base;
- for (int i = 1; i < exp; i++) {
- result *= base;
- }
- return result;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement