Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
A_141211_FuncionesVarias
//Title of this code #include <stdio.h> #include <math.h> long factorial(short n); short mcd(short x, short y); short esPrimo(short p); int main(void) { short n; long F; short a, b; printf("Valor de n ... "); scanf(" %hd", &n); F = factorial(n); printf("El factorial de %hd es %ld\n", n, F); printf("Valor de a ... "); scanf(" %hd", &a); printf("Valor de b ... "); scanf(" %hd", &b); short m = mcd(a, b); printf("El mcd de %hd y %hd es %hd\n", a, b, m); short p; printf("Valor de p ... "); scanf(" %hd", &p); if(esPrimo(p)) printf("Es PRIMO\n"); else printf("NO es PRIMO\n"); printf("\n\n\n"); short i; for(i = 0 ; i <= 20 ; i++) {N printf("%3hd --> %25ld\n", i, factorial(i)); } return 0; } long factorial(short n) { long F = 1; while(n) F *= n--; return F; } short mcd(short x, short y) { while(y) { short aux = x; x = y; y = aux % y; } return x; } short esPrimo(short p) { if(p == 1 || p == 2) return 1; short d; for(d = 2 ; d <= sqrt(p) && p % d ; d++); // if(p % d == 0) return 0; // return 1; return p % d; }
run
|
edit
|
history
|
help
0
20171117_FUNCIONES
fork
Rudra
18BCE2182 ASSESS_1 Q1-8
150114_MatrizSumaPerimetro
Project 3 Part 1 v1.6
1233333
lab 12 v0.1
Tree
Project 4 v.3