Skip to content

Instantly share code, notes, and snippets.

@rodrigomb81
Created October 5, 2015 15:25
Show Gist options
  • Save rodrigomb81/b5a9a2e7a5c31bf68cc2 to your computer and use it in GitHub Desktop.
Save rodrigomb81/b5a9a2e7a5c31bf68cc2 to your computer and use it in GitHub Desktop.
#include <stdio.h>
int esVocal(char c);
int cantidadDeVocales(char cadena[20]);
int main () {
char a[20] = {'H', 'o', 'l', 'a', '!'};
char b[20] = {'a', 'e', 'i', 'o', 'u'};
char c[20] = {'A', 'E', 'I', 'O', 'U'};
char d[] = "aeiou"; /*si la cadena esta mal inicilizada entonces da cualquier cosa ej: 7 vocales en 'aeiou'*/
printf("\"%s\" tiene %d vocales.\n", a, cantidadDeVocales(a));
printf("\"%s\" tiene %d vocales.\n", b, cantidadDeVocales(b));
printf("\"%s\" tiene %d vocales.\n", c, cantidadDeVocales(c));
printf("\"%s\" tiene %d vocales.\n", d, cantidadDeVocales(d));
return 0;
}
int esVocal(char c) {
int esVocalMayuscula = (c == 'A' || c == 'E' || c == 'I' || c == 'O' || c == 'U');
int esVocalMinuscula = (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u');
return esVocalMinuscula || esVocalMayuscula;
}
int cantidadDeVocales(char cadena[20]) {
int resultado = 0;
int i = 0;
for (i = 0; i < 20; i++) {
if (esVocal(cadena[i])) {
resultado++;
}
}
return resultado;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment