/*Elabore um algoritmo que leia uma string (um texto) e determine um valor correspondente a
quantas letras ‘a’ (maiúsculas ou minúsculas) existem na string. Calcule a fatorial do valor
determinado e mostre quantos números múltiplos de 3 existem no intervalo
entre 1 e o fatorial calculado*/
#include <stdio.h>
int fatorial(int x) {
int i, res = 1;
for (i = x; i > 1; i--) {
res = res * i;
}
return res;
}
int main(void) {
int num, fat, cont=0, contA=0, i;
char texto[100];
//scanf("%s", &texto);
//conta ocorrencias da letra "a"
for (i
= 0; i
< strlen(texto
); i
++) { if (texto[i] == 'a' || texto[i] == 'A') {
contA++;
}
}
fat = fatorial(contA);
for (i = 1; i <= fat; i++) {
if (i % 3 == 0) {
cont++;
}
}
printf ("Fatorial: %i \nQtd a: %i \nMultiplos de 3: %i", fat
, contA
, cont
); printf ("\nMultiplos de 3: %i", fat
/3);
return 0;
}
LypFbGFib3JlIHVtIGFsZ29yaXRtbyBxdWUgbGVpYSB1bWEgc3RyaW5nICh1bSB0ZXh0bykgZSBkZXRlcm1pbmUgdW0gdmFsb3IgY29ycmVzcG9uZGVudGUgYSAKcXVhbnRhcyBsZXRyYXMg4oCYYeKAmSAobWFpw7pzY3VsYXMgb3UgbWluw7pzY3VsYXMpIGV4aXN0ZW0gbmEgc3RyaW5nLiBDYWxjdWxlIGEgZmF0b3JpYWwgZG8gdmFsb3IgCmRldGVybWluYWRvIGUgbW9zdHJlIHF1YW50b3MgbsO6bWVyb3MgbcO6bHRpcGxvcyBkZSAzIGV4aXN0ZW0gbm8gaW50ZXJ2YWxvIAplbnRyZSAxIGUgbyBmYXRvcmlhbCBjYWxjdWxhZG8qLwojaW5jbHVkZSA8c3RkaW8uaD4KCmludCBmYXRvcmlhbChpbnQgeCkgewoJaW50IGksIHJlcyA9IDE7CgkKCWZvciAoaSA9IHg7IGkgPiAxOyBpLS0pIHsKCQlyZXMgPSByZXMgKiBpOwoJfQoJcmV0dXJuIHJlczsKfQoKaW50IG1haW4odm9pZCkgewoJaW50IG51bSwgZmF0LCBjb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