Created
May 28, 2019 21:18
promedio números pares
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> | |
#include <stdlib.h> | |
void main(int argc, char** argv) { | |
//crear variables | |
int i = 2; //el ejercicio empieza desde 2 | |
int suma = 0; //acumulador | |
int par = 0; //variable para determinar numero par | |
int contador = 0; //para saber cuantos numeros pares hay | |
int promedio = 0; | |
//crear ciclo for | |
for (i>=2; i<=20; i++) | |
{ | |
par = i % 2; | |
if (par == 0) | |
{ | |
suma = suma + i; | |
contador++; | |
} | |
} | |
//calculo del promedio | |
if (contador >0) | |
{ | |
promedio = suma / contador; | |
} | |
//imprimir el promedio | |
printf("\nEl promedio es: %d", promedio); | |
getch(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment