PRG29003-2022-1-02: mudanças entre as edições
Ir para navegação
Ir para pesquisar
Sem resumo de edição |
Sem resumo de edição |
||
Linha 27: | Linha 27: | ||
alfa[j]=0; | alfa[j]=0; | ||
printf("string: %s\n", alfa); | printf("string: %s\n", alfa); | ||
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; | return 0; | ||
} | } | ||
</syntaxhighlight> | </syntaxhighlight> |
Edição das 11h25min 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;
}