Created
October 30, 2019 21:08
-
-
Save jgatjens/65a34289feef627a8515f0f6744fc249 to your computer and use it in GitHub Desktop.
Examne sopresa c++
This file contains 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> | |
void examen_sorpresa(); | |
int factorial(int n); | |
char name[20]; | |
int dia, mes, year, edad, sum, sum_fact, i, fact; | |
char pregunta; | |
int main() { | |
examen_sorpresa(); | |
return 0; | |
} | |
void examen_sorpresa() { | |
printf("nombre amigo: "); | |
scanf("%s", name); | |
printf("fecha de nacimiento (dia):"); | |
scanf("%d", &dia); | |
printf("fecha de nacimiento (mes):"); | |
scanf("%d", &mes); | |
printf("fecha de nacimiento (año):"); | |
scanf("%d", &year); | |
sum = dia + mes + year; | |
edad = 2019 - year; | |
sum_fact = factorial(sum); | |
printf("nombre: %s \n", name); | |
printf("edad actual: %d \n", edad); | |
printf("sumatoria fecha de nacimiento: %d \n", sum); | |
printf("factorial fecha de nacimiento: %d \n", sum_fact); | |
printf("Desea hacer el la operacion otra ves (y/n):"); | |
scanf("%s", &pregunta); | |
if (pregunta == 'y') { | |
examen_sorpresa(); | |
} else { | |
printf("\n\n===> gracias por preferisnos !!\n\n"); | |
} | |
} | |
int factorial(int n) { | |
if(n < 0) return 0; | |
else if(n > 1) return n*factorial(n-1); | |
return 1; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment