Created
October 22, 2014 19:33
-
-
Save Pierry/15305c2c5f42a8ca81bf to your computer and use it in GitHub Desktop.
Verifica quantas vezes o numero N se repete na sequência M
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> | |
#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