Mudanças entre as edições de "PRG29003-2022-1-02"
Ir para navegação
Ir para pesquisar
(2 revisões intermediárias pelo mesmo usuário não estão sendo mostradas) | |||
Linha 28: | Linha 28: | ||
printf("string: %s\n", alfa); | printf("string: %s\n", alfa); | ||
return 0; | return 0; | ||
+ | } | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | <syntaxhighlight lang=c> | ||
+ | #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; | ||
+ | } | ||
+ | </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 lang=c++> | ||
+ | #include <iostream> | ||
+ | #include <string> | ||
+ | #include <stdlib.h> | ||
+ | |||
+ | using namespace std; | ||
+ | |||
+ | const string niveis[3]={ | ||
+ | "subindo", | ||
+ | "estacionario", | ||
+ | "baixando", | ||
+ | }; | ||
+ | |||
+ | const string msgs_meteo[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 ler_dados(const string aux) | ||
+ | { | ||
+ | int i; | ||
+ | for(i=0;i<3;i++) { | ||
+ | if (niveis[i] == aux) { | ||
+ | break; | ||
+ | } | ||
+ | } | ||
+ | return i; | ||
+ | } | ||
+ | |||
+ | int main() { | ||
+ | int i, temp, bar; | ||
+ | string aux; | ||
+ | |||
+ | cout << "Entre com a temperatura"; | ||
+ | cin >> aux; | ||
+ | temp = ler_dados(aux); | ||
+ | if (temp>3) {cout << "Entrada incorreta"; exit(-1);} | ||
+ | |||
+ | cout << "Entre com a pressão"; | ||
+ | cin >> aux; | ||
+ | bar = ler_dados(aux); | ||
+ | if (temp>3) {cout << "Entrada incorreta"; exit(-1);} | ||
+ | |||
+ | cout << msgs_meteo[temp][bar]; | ||
+ | return 0; | ||
} | } | ||
</syntaxhighlight> | </syntaxhighlight> |
Edição atual tal como às 17h28min de 11 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;
}
#include <iostream>
#include <string>
#include <stdlib.h>
using namespace std;
const string niveis[3]={
"subindo",
"estacionario",
"baixando",
};
const string msgs_meteo[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 ler_dados(const string aux)
{
int i;
for(i=0;i<3;i++) {
if (niveis[i] == aux) {
break;
}
}
return i;
}
int main() {
int i, temp, bar;
string aux;
cout << "Entre com a temperatura";
cin >> aux;
temp = ler_dados(aux);
if (temp>3) {cout << "Entrada incorreta"; exit(-1);}
cout << "Entre com a pressão";
cin >> aux;
bar = ler_dados(aux);
if (temp>3) {cout << "Entrada incorreta"; exit(-1);}
cout << msgs_meteo[temp][bar];
return 0;
}