Skip to content

Instantly share code, notes, and snippets.

@Pierry
Created October 22, 2014 19:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Pierry/15305c2c5f42a8ca81bf to your computer and use it in GitHub Desktop.
Save Pierry/15305c2c5f42a8ca81bf to your computer and use it in GitHub Desktop.
Verifica quantas vezes o numero N se repete na sequência M
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <ctype.h>
#include <string.h>
int main()
{
void leitura(char *valor);
int varrerString(char valor);
char *valor;
leitura(&valor);
printf("\n\nNa Sequencia 762021192 o numero %c ocorre %d vezes", valor, varrerString(valor));
return 1;
}
void leitura(char *valor){
char valorRecebido[2];
printf("\nQual numero deseja verificar?\n\n");
fgets(valorRecebido, 2, stdin);
int aux = valorRecebido[0] - '0';
while(aux <= 0){
printf("\nDeve ser maior que zero, digite novamente?\n\n");
fgets(valorRecebido, 2, stdin);
aux = valorRecebido[0] - '0';
}
*valor = valorRecebido[0];
}
int varrerString(char valor){
char sequencia[9] = "762021192";
int tamanho = strlen(sequencia);
int total=0;
int i=0;
for(;i < tamanho; i++){
char aux = sequencia[i];
if(aux == valor){
total++;
}
}
return total;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment