Mudanças entre as edições de "PRG29003-2022-1-02"
Ir para navegação
Ir para pesquisar
Linha 58: | Linha 58: | ||
return 0; | return 0; | ||
} | } | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | <syntaxhighlight lang=c> | ||
+ | #include <stdio.h> | ||
+ | #include <string.h> | ||
+ | #include <stdlib.h> | ||
+ | |||
+ | char *mensagens[3][3] = { | ||
+ | "Tempo bom, ventos quentes e secos", "Tempo Bom, ventos de leste frescos ", "Tempo bom, ventos de sul e sudeste", | ||
+ | "Tempo mudando para bom, ventos de leste", "Tempo incerto, ventos variáveis", "Chuva provável, ventos de sul e sudeste", | ||
+ | "msg7", "msg8", "msg9", | ||
+ | }; | ||
+ | |||
+ | int main() { | ||
+ | int i, j, valor_pressao, valor_temperatura; | ||
+ | char barometro[15], | ||
+ | temperatura[15]; | ||
+ | |||
+ | printf("Entre com a pressão\n"); | ||
+ | scanf("%14s", barometro); | ||
+ | if (strcmp(barometro, "subindo") == 0) | ||
+ | valor_pressao = 0; | ||
+ | else if(strcmp(barometro,"estacionario")==0) | ||
+ | valor_pressao = 1; | ||
+ | else if(strcmp(barometro,"baixando")==0) | ||
+ | valor_pressao = 2; | ||
+ | else { | ||
+ | printf("Entrada inválida da pressão"); | ||
+ | exit (1); | ||
+ | } | ||
+ | |||
+ | printf("Entre com a temperatura\n"); | ||
+ | scanf("%14s", temperatura); | ||
+ | if(strcmp(temperatura,"subindo")==0) | ||
+ | valor_temperatura = 0; | ||
+ | else if(strcmp(temperatura,"estacionario")==0) | ||
+ | valor_temperatura = 1; | ||
+ | else if(strcmp(temperatura,"baixando")==0) | ||
+ | valor_temperatura = 2; | ||
+ | else { | ||
+ | printf("Entrada inválida da temperatura"); | ||
+ | exit (1); | ||
+ | } | ||
+ | |||
+ | printf("%s\n", mensagens[valor_pressao][valor_temperatura]); | ||
+ | |||
+ | return 0; | ||
+ | } | ||
+ | |||
</syntaxhighlight> | </syntaxhighlight> |
Edição das 14h57min de 7 de abril de 2022
#include <stdio.h>
#include <string.h>
int main(){
char alfa[50]="alo mundo cruel !!";
int i,j,tam,first;
first=0;
i=0;
j=0;
while (alfa[i]!='\0') {
if (alfa[i]!=' ') {
alfa[j] = alfa[i]; /* regra geral - copia */
j++;
first=1;
} else if (first==1){
alfa[j] = alfa[i]; /* copia */
first=0;
j++;
}
i++;
}
if (j!=0 && alfa[j-1] == ' ')
alfa[j-1]='\0';
else
alfa[j]=0;
printf("string: %s\n", alfa);
return 0;
}
#include <stdio.h>
float dinheiro[10]={0.01, 0.05, 0.25, 0.5, 1,2,5,10,50,100};
int main()
{
float valor=3.57, troco, pag=10;
int i,qtdade;
troco = pag-valor;
i=9;
while (troco>=0.01) {
qtdade = (int)(troco/dinheiro[i]);
if ( qtdade >= 1) {
if (dinheiro[i] > 1)
printf("%d cédula(s) de R$ %f\n", qtdade, dinheiro[i]);
else
printf("%d moeda(s) de R$ %f\n", qtdade, dinheiro[i]);
troco = troco - qtdade * dinheiro[i];
}
i--;
}
return 0;
}
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
char *mensagens[3][3] = {
"Tempo bom, ventos quentes e secos", "Tempo Bom, ventos de leste frescos ", "Tempo bom, ventos de sul e sudeste",
"Tempo mudando para bom, ventos de leste", "Tempo incerto, ventos variáveis", "Chuva provável, ventos de sul e sudeste",
"msg7", "msg8", "msg9",
};
int main() {
int i, j, valor_pressao, valor_temperatura;
char barometro[15],
temperatura[15];
printf("Entre com a pressão\n");
scanf("%14s", barometro);
if (strcmp(barometro, "subindo") == 0)
valor_pressao = 0;
else if(strcmp(barometro,"estacionario")==0)
valor_pressao = 1;
else if(strcmp(barometro,"baixando")==0)
valor_pressao = 2;
else {
printf("Entrada inválida da pressão");
exit (1);
}
printf("Entre com a temperatura\n");
scanf("%14s", temperatura);
if(strcmp(temperatura,"subindo")==0)
valor_temperatura = 0;
else if(strcmp(temperatura,"estacionario")==0)
valor_temperatura = 1;
else if(strcmp(temperatura,"baixando")==0)
valor_temperatura = 2;
else {
printf("Entrada inválida da temperatura");
exit (1);
}
printf("%s\n", mensagens[valor_pressao][valor_temperatura]);
return 0;
}