Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <conio2.h>
- #include <string.h>
- #include <ctype.h>
- #define LIM 101
- void NumVogais(void)
- {
- int i, cont = 0;
- char str[LIM];
- clrscr();
- printf("Digite uma string:\n");
- fflush(stdin);
- gets(str);
- for(i = 0; i < strlen(str); i++)
- if(toupper(str[i]) == 'A' ||
- toupper(str[i]) == 'E' ||
- toupper(str[i]) == 'I' ||
- toupper(str[i]) == 'O' ||
- toupper(str[i]) == 'U' )
- cont++;
- printf("%d vogais na frase\n", cont);
- getch();
- }
- void Formata(void)
- {
- char str[LIM];
- int i;
- clrscr();
- printf("Digite um texto:\n");
- fflush(stdin);
- gets(str);
- str[0] = toupper(str[0]);
- for(i = 1; i < strlen(str); i++)
- if(toupper(str[i]) >= 65 && toupper(str[i]) <= 92)
- {
- if(str[i - 1] == ' ')
- str[i] = toupper(str[i]);
- else
- str[i] = tolower(str[i]);
- }
- printf("%s\n", str);
- getch();
- }
- void ContaPalavras(void)
- {
- int i, cont = 0;
- char str[LIM];
- clrscr();
- printf("Digite uma string:\n");
- fflush(stdin);
- gets(str);
- if(toupper(str[0]) >= 65 && toupper(str[0]) <= 92)
- cont++;
- for(i = 1; i < strlen(str); i++)
- if(toupper(str[i]) >= 65 && toupper(str[i]) <= 92)
- if(str[i - 1] == ' ')
- cont++;
- printf("%d palavras\n", cont);
- getch();
- }
- void Duplica(void)
- {
- int i, j;
- char str[LIM];
- clrscr();
- printf("Digite o texto:\n");
- fflush(stdin);
- gets(str);
- for(i = 0; i < strlen(str); i += 2)
- {
- if(toupper(str[i]) >= 65 && toupper(str[i]) <= 92)
- {
- for(j = strlen(str); j > i; j--)
- str[j + 1] = str[j];
- str[i + 1] = str[i];
- }
- }
- printf("%s\n", str);
- getch();
- }
- void ContaLetrasDif(void)
- {
- int i, cont, j, pos, tot = 0;
- char str[20];
- clrscr();
- printf("Digite uma string:\n");
- fflush(stdin);
- gets(str);
- for(i = 0; i < strlen(str); i++)
- {
- pos = 0;
- cont = 0;
- while(pos < strlen(str))
- {
- if(toupper(str[i]) == toupper(str[pos]))
- cont++;
- pos++;
- }
- if(cont == 1)
- tot++;
- }
- printf("%d letras diferentes\n");
- getch();
- }
- void Palindromo(void)
- {
- char str[LIM], aux[LIM];
- int i, j, k, TLP = 0;
- clrscr();
- printf("Digite uma string:\n");
- fflush(stdin);
- gets(str);
- for(i = 0; i <= strlen(str); i++)
- {
- if(toupper(str[i]) >= 65 && toupper(str[i]) <= 92)
- aux[TLP++] = str[i];
- else if(str[i] == ' ' || str[i] == '\0')
- {
- aux[TLP] = '\0';
- for(j = 0, k = strlen(aux) - 1; str[j] == str[k] && j <= k; j++, k--)
- ;
- if(j > k)
- printf("%s e palindromo\n", aux);
- TLP = 0;
- }
- }
- getch();
- }
- void TiraEspacos(void)
- {
- char Entrada[LIM], Saida[LIM];
- int i, pos = 0;
- clrscr();
- printf("Digite o texto:\n");
- fflush(stdin);
- gets(Entrada);
- for(i = 0; i < strlen(Entrada); i++)
- if(Entrada[i] != ' ')
- Saida[pos++] = Entrada[i];
- Saida[pos] = '\0';
- printf("\n%s\n", Saida);
- getch();
- }
- char Menu(void)
- {
- clrscr();
- printf("Digite a opcao desejada ou X para sair:\n");
- printf("[1] - Exercicio 1\n");
- printf("[2] - Exercicio 2\n");
- printf("[3] - Exercicio 3\n");
- printf("[4] - Exercicio 4\n");
- printf("[5] - Exercicio 5\n");
- printf("[6] - Exercicio 6\n");
- printf("[7] - Exercicio 7\n");
- printf("[8] - Exercicio 8\n");
- return toupper(getche());
- }
- void Executa(void)
- {
- char Op;
- Op = Menu();
- while(Op != 'X')
- {
- switch(Op)
- {
- case '1':
- NumVogais();
- break;
- case '2':
- break;
- case '3':
- Formata();
- break;
- case '4':
- ContaPalavras();
- break;
- case '5':
- ContaLetrasDif();
- break;
- case '6':
- Palindromo();
- break;
- case '7':
- TiraEspacos();
- break;
- case '8':
- Duplica();
- break;
- default:
- printf("\nOpcao Invalida\n");
- }
- Op = Menu();
- }
- getch();
- }
- int main(void)
- {
- Executa();
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement