Vous êtes sur la page 1sur 6

LINGUAGENS DE PROGRAMAÇÃO

1º TRABALHO REFERENTE A SEGUNDA UNIDADE

ALUNO: RAIRO SAMUEL MORAIS SOUZA

MATRICULA: 200506733

Obs.: Os programas a seguir foram feitos e compilados por base do


compilador DEV C++. Podendo haver assim algumas diferenças.

1. A partir do vetor {10, 2, 4, 5, 30}, imprima na ordem de definição do vetor e


na ordem inversa da definição.

RESPOSTA:

#include <stdio.h>

main() {
int vetor[] = {10, 2, 4, 5, 30};
int tamanho = 5;
int indice;

for (indice = 0; indice < tamanho; indice++) {


printf("%d ", vetor[indice]);
}
printf("\n");

for (indice = tamanho-1; indice >= 0; indice--) {


printf("%d ", vetor[indice]);
}
printf("\n");

system("pause");
}
2. Escreva um programa que a partir de um cadeia de caractere definida como
{‘a’, ‘v’, ‘a’, ‘l’, ‘i’, ‘a’, ‘c’, ‘a’, ‘o’}, imprima em sua ordem de definição e na
ordem inversa de definição.

RESPOSTA:

#include <stdio.h>
main() {
char vetor[] = {'a', 'v', 'a', 'l', 'i', 'a', 'c', 'a', 'o'};
char tamanho = 9;
char indice;
for (indice = 0; indice < tamanho; indice++) {
printf("%c ", vetor[indice]);
}
printf("\n");
for (indice = tamanho-1; indice >= 0; indice--) {
printf("%c ", vetor[indice]);
}
printf("\n");
system("pause");
}
3. Escreva um programa que leia 10 valores floats e os armazene em um vetor.
Depois calcule e imprima a média, o desvio padrão e a mediana destes
valores.

RESPOSTA:

#include <stdio.h>

main(){
int tamanho=10;
int indice=0;
float vetor[tamanho], var[tamanho], somavar=0, raiz, desv;

for(indice=0; indice<tamanho; indice++){


vetor[indice]=0.0f;
}
for(indice=0; indice<tamanho; indice++){
printf("DIGITE VALOR DO VETOR(%d): ", indice);
scanf("%f",&vetor[indice]);
}
float soma=0.0f, media=0.0f;
for(indice=0; indice<tamanho; indice++){
soma+=vetor[indice];
}
media=soma/tamanho;
printf("\n");
printf("1.) A media dos valores: %f\n", media);
for(indice=0; indice<tamanho; indice++){
var[indice]=(((vetor[indice])-media)*((vetor[indice])-media));
somavar=(somavar+var[indice]);
}
raiz=sqrt(somavar);
desv=raiz/(tamanho-1);
printf("2.) O valor do desvio padrão: %f\n",desv);
printf("\n");
system("pause");
}
4. Escreva um programa que leia duas cadeias de caractere do teclado e
verifique se um é um anagrama do outro (espaços devem ser ignorados).

RESPOSTA:
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>

int main(){
int let1[26],let2[26], y, i;
char c;
int igual=1;
for(i=0;i<26;i++) let1[i]=let2[i]=0;
printf("DIGITE A PRIMEIRA CADEIA DE CARACTERES\n");
while(1){
c=getche();
y=c;
if(y<20){
break;
}
if((y>64 && y<92) || (y>96 && y<124)){
if(y<92) y=y+32;
y=y-97;
let1[y]++;
}
}
printf("\nDIGITE A SEGUNDA CADEIA DE CARACTERES\n");
while(1){
c=getche();
y=(int)c;
if(y<20){
break;
}
if((y>64 && y<92) || (y>96 && y<124)){
if(y<92) y=y+32;
y=y-97;
let2[y]++;
}
}
for(i=0;i<26;i++){
if(let1[i]!=let2[i]){
igual=0;
break;
}
}
if(igual) printf("\n AS SEQUENCIAS SÃO ANAGRAMAS \n\n");
else printf("\n AS SEQUENCIAS NÃO SÃO ANAGRAMAS\n\n");
system("pause");
}

5. A partir do vetor {10, 2, 4, 5, 30}, imprima na ordem crescente e decrescente


dos valores.

RESPOSTA:

#include <stdio.h>

int qtd(void);

void main(){

register int x, y;

int qnum=5;

int numero[5]={10,2,4,5,30};

int temp;

y=qnum;

x=0;

for(y=5; y>0; y--){

for(x=0; x<y; x++){

if(numero[x]>numero[x+1]){

temp=numero[x];

numero[x]=numero[x+1];

numero[x+1]=temp;

for (x=0; x<qnum; x++){


printf(" %d",numero[ x ]);

printf("\n");

y=4;

while (y>-1){

printf(" %d",numero[y]);

y--;

printf("\n");

printf("\n \n");

system("pause");

Vous aimerez peut-être aussi