Created
October 23, 2019 05:12
-
-
Save jgatjens/648de869f437cf08ee0665346a3d1711 to your computer and use it in GitHub Desktop.
C++ exercises
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<stdio.h> | |
#include<math.h> | |
void one_thousand_square(); | |
void fx(); | |
void multiplication_table(); | |
void factorial(); | |
int main() { | |
int n, opcion; | |
do { | |
printf("\n"); | |
printf("<======= MENU =======>"); | |
printf("\n"); | |
printf("1. Calcular cuadrados del 1 al 1000\n"); | |
printf("2. Calcular tabla de multiplicar\n"); | |
printf("3. Calcular F(x)\n"); | |
printf("4. Calcular N! desde 1! hasta 10\n"); | |
printf("5. Salir\n"); | |
printf("Introducir opcion (1-5): "); | |
scanf("%d", &n); | |
switch (n) { | |
case 1: | |
one_thousand_square(); | |
break; | |
case 2: | |
fx(); | |
break; | |
case 3: | |
multiplication_table(); | |
break; | |
case 4: | |
factorial(); | |
break; | |
case 5: | |
return 0; | |
} | |
} while(opcion != 5); | |
} | |
void one_thousand_square() { | |
int x; | |
for (x=1; x <= 100; x++){ | |
printf("%d :pow= %.f \n", x, pow(x,2)); | |
} | |
printf("\n"); | |
} | |
void fx() { | |
int x, F; | |
printf("Introduzca X:"); | |
scanf("%d", &x); | |
F=((x*x*x)+(x*x)-5); | |
printf("El F(x)=x^3+x^2-5: %d\n", F); | |
} | |
void multiplication_table() { | |
int z, x = 0; | |
printf("Ingrese el numero de la tabla deseada: "); | |
scanf("%d", &z); | |
while(x <= 11) { | |
x++; | |
printf("La tabla elegida es:%d\n", z*x); | |
} | |
} | |
void factorial() { | |
int N1=1; | |
int N2=2*1; | |
int N3=3*2*1; | |
int N4=4*3*2*1; | |
int N5=5*4*3*2*1; | |
int N6=6*5*4*3*2*1; | |
int N7=7*6*5*4*3*2*1; | |
int N8=8*6*5*4*3*2*1; | |
int N9=9*8*7*6*5*4*3*2*1; | |
int N10=10*9*8*7*6*5*4*3*2*1; | |
printf("\n1!=%d\n2!=%d\n3!=%d\n4!=%d\n5!=%d\n6!=%d\n7!=%d\n8!=%d\n9!=%d\n10!=%d\n",N1,N2,N3,N4,N5,N6,N7,N8,N9,N10); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment