Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <ctype.h>
- #define resp 11 //Define da questão 6
- int main(){
- char gabarito[resp]; //Questão 6
- int qntaluno;
- printf("\t\tDigite o gabarito da prova(A, B, C ou D)");
- for(int i=0;i<resp-1;i++){ //laço de leitura dos caracteres do gabarito
- printf("\nResposta questao %d: ", i+1);
- scanf("%c", &gabarito[i]);
- setbuf(stdin, NULL);
- }
- system("cls"); //desabilite caso queira fazer teste de mesa
- printf("Informe a quantidade de alunos: ");
- scanf("%d", &qntaluno);
- setbuf(stdin, NULL);
- char nomealuno[qntaluno][129], resposta; //somente após leitura da quantidade de alunos pode-se declarar as variáveis
- int nota[qntaluno][1]={0};
- system("cls");
- for(int i=0;i<qntaluno;i++){
- printf("Informe o nome do aluno: ");
- gets(nomealuno[i]);
- for(int j=0;j<resp-1;j++){
- printf("Informe a resposta de %s para a questão %d: ", nomealuno[i], j+1); //algoritmo da bolha para leitura das notas
- resposta=getchar();
- setbuf(stdin, NULL); //sempre limpe o buffer
- if(resposta==gabarito[j]){
- nota[i][0]++;
- }
- system("cls");
- }
- }
- printf("\t\tNotas dos alunos\n");
- for(int i=0;i<qntaluno;i++){
- printf("\n|%s\t|%d|", nomealuno[i], nota[i][0]); //impressão dos nomes e notas
- }
- printf("\n");
- /*
- int tam, flag=1; //Questão 5
- printf("Quantidade strings: ");
- scanf("%d", &tam);
- setbuf(stdin, NULL);
- char string[tam][129], stringaux[129]; //matriz de string(trabalha usando apenas o 1 índice)
- for(int i=0;i<tam;i++){
- printf("Digite um nome qualquer: ");
- gets(string[i]);
- }
- //for(int i=0;i<tam;i++){
- // printf("%s", string[i]);
- //}
- for(;flag==1;){
- flag=0; //algoritmo da bolha, controlado por uma flag
- for(int j=0;j<tam-1;j++){
- //printf("(%d) ", strcasecmp(string[j], string[j+1]));
- if(strcasecmp(string[j], string[j+1])>0){ //se a subtração de uma string por outra for acima de 0
- strcpy(stringaux, string[j]); //função strcpy, para atribuir uma string a outra string
- strcpy(string[j], string[j+1]);
- strcpy(string[j+1], stringaux);
- flag=1; //caso tenha atendido a condição a flag faz com que o algoritmo continue
- }
- }
- }
- printf("\t\tStrings em ordem alfabetica\n");
- for(int i=0; i<tam;i++){ //imprime as strings
- printf("%s\n", string[i]);
- }
- */
- /*
- char string[100], carac, vogais[]={'A','E','I','O','U'}; //questão 4
- int tam;
- printf("Digite uma frase: ");
- gets(string);
- setbuf(stdin, NULL);
- tam=strlen(string);
- printf("Insira um caracter qualquer: ");
- scanf("%c", &carac);
- for(int i=0;i<tam;i++){ //rotina de verificação de vogais presentes na string e substituição
- for(int j=0;j<5;j++){
- if(toupper(string[i])==vogais[j]){
- string[i]=carac;
- }
- }
- //if(string[i]=='a' || string[i]=='A' || string[i]=='e' || string[i]=='E' || string[i]=='i' || string[i]=='I' || string[i]=='o' || string[i]=='O' || string[i]=='u' || string[i]=='U')
- // string[i]=carac;
- }
- printf("\n%s", string);
- */
- /*
- char string[100]; //questão 3
- int tam;
- printf(">> ");
- gets(string);
- tam=strlen(string); //função para identificar o tamnho da string/atribuição na variável tam
- char stringaux[tam]; //stringaux para armazenar a string invertida
- strcpy(stringaux, string);
- for(int i=tam-1, j=0;i>-1;i--,j++){ //rotina de inversão de string
- string[j]=stringaux[i];
- //printf("%c", stringaux[j]);
- }
- printf("\n\n%s", string);
- */
- /*char string[100]; //Questão 2
- int tam;
- printf(">> ");
- gets(string);
- setbuf(stdin, NULL); //limpa buffer teclado(stdin)
- tam=strlen(string); //função tamanho da string
- for(int i=tam-1;i>=0;i--){
- printf("%c", string[i]); //mostra a string ao contrário
- }*/
- /*
- char string[10]; //Questão 1
- printf(">> ");
- gets(string);
- for(int i=0;i<4;i++){
- printf("%c", string[i]);
- }*/
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement