Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Polidivisible
#include <stdio.h> #define mensaje1 printf("%lu ES un numero POLIDIVISIBLE\n",numero) #define mensaje2 printf("%lu NO ES un numero POLIDIVISIBLE\n",numero) unsigned short esPolidivisible(unsigned long); unsigned short calcularLargo(unsigned long); int main() { unsigned long numero; do { scanf("%lu", &numero); if (numero == 0) break; esPolidivisible(numero) ? mensaje1 : mensaje2; } while (1); printf("FIN"); return 0; } unsigned short esPolidivisible(unsigned long copiaNumero) { unsigned short largo = calcularLargo(copiaNumero); unsigned short i; for (i = largo ; i >= 2 ; i--) { if (copiaNumero % i != 0) return 0; else copiaNumero /= 10; } return 1; } unsigned short calcularLargo(register unsigned long copiaNumero) { unsigned short largo = 0; while (copiaNumero != 0) { largo++; copiaNumero /= 10; } return largo; }
run
|
edit
|
history
|
help
0
exercises
Lab 5 HW Spring 2017 v0.5
C - printf precision modifiers
Serie de Fibonacci
14th Dec Project1 v0.2
6 ejercicio trabajo semanal 4
150113_CribaErastotenes
RadixSort
session1
First program.c