Lista_1
Autor: André.IAT | Publicado: 2010-09-07T20:18:00-07:00

&nbsp;&nbsp; &nbsp;#include&lt;stdio.h&gt;//usada para as funções printf, scanf, if, for.&nbsp;&nbsp; &nbsp;#include&lt;conio.h&gt;//usada para a função getch();&nbsp;&nbsp; &nbsp;/*1) Faça um programa que calcule a média aritmética de 45 alunos do curso de LP1. Use FOR.*/&nbsp;&nbsp; &nbsp;main ()&nbsp;&nbsp; &nbsp;{&nbsp;&nbsp; &nbsp;int x,s;&nbsp;&nbsp;&nbsp; &nbsp;s=0;&nbsp;&nbsp; &nbsp;float media,nota,soma;&nbsp;&nbsp; &nbsp;for(x=1;x&lt;=5;x++){&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; printf("Entre com a nota do %d aluno :",x);&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; scanf("%f",&amp;nota);&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; soma=soma+nota;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; s++;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; media=soma/s;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; printf("A media aritmetica dos %d alunos foi :%.2f",s,media);&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;getch();&nbsp;&nbsp; &nbsp;}--------------------------------------------------------------------------------------------------------------------------------------------------------------------
&nbsp;&nbsp; &nbsp;#include&lt;stdio.h&gt;&nbsp;&nbsp; &nbsp;#include&lt;conio.h&gt;&nbsp;&nbsp; &nbsp;/*2) Faça um programa que imprima o(s) número(s) dentro do intervalo entre 600 e 700&nbsp;&nbsp; &nbsp; que sejam múltiplos de 5 e também de 7.*/&nbsp;&nbsp; &nbsp;main ()&nbsp;&nbsp; &nbsp;{&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;int x,five,sevem;&nbsp;&nbsp; &nbsp;printf("||---- Multiplos de 5 e 7 ----||\n");&nbsp;&nbsp; &nbsp;for(x=600;x&lt;=700;x++){&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if ((x%7)==0&amp;&amp;(x%5)==0)&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; printf("\n\n%d\n",x);&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;printf("\n\n||----------- End -----------||");&nbsp;&nbsp; &nbsp;getch();&nbsp;&nbsp; &nbsp;}
--------------------------------------------------------------------------------------------------------------------------------------------------------------------
&nbsp;&nbsp; &nbsp;#include&lt;stdio.h&gt;&nbsp;&nbsp; &nbsp;#include&lt;conio.h&gt;&nbsp;&nbsp; &nbsp;/*3) Faça um programa que, dado um número, imprima a sua tabuada completa. */&nbsp;&nbsp; &nbsp;main ()&nbsp;&nbsp; &nbsp;{&nbsp;&nbsp; &nbsp;int x,n,res;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;printf("Entre com um numero :");&nbsp;&nbsp; &nbsp;scanf("%d",&amp;n);&nbsp;&nbsp; &nbsp;printf("||--- Tabuada ---||\n");&nbsp;&nbsp; &nbsp;for(x=0;x&lt;=n;x++){&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;res=n*x;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;printf("%d x %d = %d\n", n, x, res);&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}&nbsp;&nbsp; &nbsp;printf("||----- End -----||");&nbsp;&nbsp; &nbsp;getch();&nbsp;&nbsp; &nbsp;}
--------------------------------------------------------------------------------------------------------------------------------------------------------------------
&nbsp;&nbsp; &nbsp;#include&lt;stdio.h&gt;&nbsp;&nbsp; &nbsp;#include&lt;conio.h&gt;&nbsp;&nbsp; &nbsp;/*5) Faça um programa que seja capaz de calcular o resultado de uma operação de&nbsp;&nbsp; &nbsp;multiplicação (x vezes y), utilizando-se para isso apenas do operador de soma (+).*/&nbsp;&nbsp; &nbsp;main ()&nbsp;&nbsp; &nbsp;{&nbsp;&nbsp; &nbsp;int x,a,b,res=0;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;printf("Entre com um numero :");&nbsp;&nbsp; &nbsp;scanf("%d",&amp;a);&nbsp;&nbsp; &nbsp;printf("x ");&nbsp;&nbsp; &nbsp;scanf("%d",&amp;b);&nbsp;&nbsp; &nbsp;printf("||-------- Multiplica somando ----------||\n");&nbsp;&nbsp; &nbsp;for(x=1;x&lt;=b;x++){&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;res=res+a;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;printf("%d x %d = %d\n",a,b,res);&nbsp;&nbsp; &nbsp;printf("||----- End -----||");&nbsp;&nbsp; &nbsp;getch();&nbsp;&nbsp; &nbsp;}
--------------------------------------------------------------------------------------------------------------------------------------------------------------------
&nbsp;&nbsp; &nbsp;#include&lt;stdio.h&gt;&nbsp;&nbsp; &nbsp;#include&lt;conio.h&gt;&nbsp;&nbsp; &nbsp;/*5) Faça um programa que seja capaz de calcular o resultado de uma operação de&nbsp;&nbsp; &nbsp;multiplicação (x vezes y), utilizando-se para isso apenas do operador de soma (+).*/&nbsp;&nbsp; &nbsp;main ()&nbsp;&nbsp; &nbsp;{&nbsp;&nbsp; &nbsp;int x,a,b,res=0;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;printf("Entre com um numero :");&nbsp;&nbsp; &nbsp;scanf("%d",&amp;a);&nbsp;&nbsp; &nbsp;printf("x ");&nbsp;&nbsp; &nbsp;scanf("%d",&amp;b);&nbsp;&nbsp; &nbsp;printf("||-------- Multiplica somando ----------||\n");&nbsp;&nbsp; &nbsp;for(x=1;x&lt;=b;x++){&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;res=res+a;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;printf("%d x %d = %d\n",a,b,res);&nbsp;&nbsp; &nbsp;printf("||----- End -----||");&nbsp;&nbsp; &nbsp;getch();&nbsp;&nbsp; &nbsp;}
--------------------------------------------------------------------------------------------------------------------------------------------------------------------
&nbsp;&nbsp; &nbsp;#include&lt;stdio.h&gt;&nbsp;&nbsp; &nbsp;#include&lt;conio.h&gt;&nbsp;&nbsp; &nbsp;/*6) Faça um programa que seja capaz de calcular o resultado de uma operação&nbsp;&nbsp;&nbsp; &nbsp;de divisão inteira (x dividido y), utilizando-se para isso apenas do operador de subtração (-).
&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;Ex.: 12 / 3 = 4 = 12-3=9-3=6-3=3-3=0 (4 vezes)*/&nbsp;&nbsp; &nbsp;main ()&nbsp;&nbsp; &nbsp;{&nbsp;&nbsp; &nbsp;int a,b,s,x;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;printf("Entre com um numero :");&nbsp;&nbsp; &nbsp;scanf("%d",&amp;a);&nbsp;&nbsp; &nbsp;printf("/ ");&nbsp;&nbsp; &nbsp;scanf("%d",&amp;b);&nbsp;&nbsp; &nbsp;s=0;&nbsp;&nbsp; &nbsp;printf("||-------- Dividir subtraindo ----------||\n");&nbsp;&nbsp; &nbsp;x=a;&nbsp;&nbsp; &nbsp;do{&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;a=a-b;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;s++;&nbsp;&nbsp; &nbsp;}while(a&gt;0);&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;printf("%d / %d = %d \n",x,b,s);&nbsp;&nbsp; &nbsp;printf("||----- End -----||");&nbsp;&nbsp; &nbsp;getch();&nbsp;&nbsp; &nbsp;}
--------------------------------------------------------------------------------------------------------------------------------------------------------------------
&nbsp;&nbsp; /*7)Leia um numero N (inteiro, positivo &gt;5). Depois, leia para um determinado&nbsp;&nbsp;&nbsp; &nbsp;grupo de pessoas (N) as seguintes informações:&nbsp;&nbsp; &nbsp;Idade&nbsp;&nbsp;&nbsp; &nbsp;Peso&nbsp;&nbsp; &nbsp;Sexo&nbsp;&nbsp; &nbsp;Este programa deve fornecer como saída:&nbsp;&nbsp; &nbsp;a) A média dos pesos dos homens;&nbsp;&nbsp; &nbsp;b) A média das idades das mulheres;&nbsp;&nbsp; &nbsp;c) Quantas mulheres acima de 25 anos;*/&nbsp;&nbsp; &nbsp;#include&lt;stdio.h&gt;&nbsp;&nbsp; &nbsp;#include&lt;string.h&gt;&nbsp;&nbsp; &nbsp;#include&lt;conio.h&gt;&nbsp;&nbsp; &nbsp;main ()&nbsp;&nbsp; &nbsp;{&nbsp;&nbsp; &nbsp;int idade[100],sexo[100];&nbsp;&nbsp; &nbsp;int x=0,n=0,s=0,i=0,m=0,midade=0;&nbsp;&nbsp; &nbsp;float tidade=0,total_peso=0,peso[100];&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;printf("Entre com um numero &gt; 5: ");&nbsp;&nbsp; &nbsp;inicio:&nbsp;&nbsp; &nbsp;scanf("%d",&amp;n);&nbsp;&nbsp; &nbsp;if(n&lt;=5){&nbsp;&nbsp; &nbsp;printf("Voce digitou um numero menor que 5 tente novamente!\n");&nbsp;&nbsp; &nbsp;goto inicio;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}&nbsp;&nbsp; &nbsp;for(x=1;x&lt;=n;x++){&nbsp;&nbsp; &nbsp;printf("Digite a Idade :");&nbsp;&nbsp; &nbsp;scanf("%d",&amp;idade[x]);&nbsp;&nbsp; &nbsp;printf("Digite o Peso :");&nbsp;&nbsp; &nbsp;scanf("%f",&amp;peso[x]);&nbsp;&nbsp; &nbsp;sex:&nbsp;&nbsp; &nbsp;printf("Digite 1 para homem ou 2 para mulher:");&nbsp;&nbsp; &nbsp;scanf("%d",&amp;sexo[x]);&nbsp;&nbsp; &nbsp;if((sexo[x]!=1)&amp;&amp;(sexo[x]!=2)){&nbsp;&nbsp; &nbsp;printf("Opcão invalida digite novamente!!\n");&nbsp;&nbsp; &nbsp;goto sex;&nbsp;&nbsp; &nbsp;}&nbsp;&nbsp; &nbsp;printf("|-------------------------------------------------------------------|\n");&nbsp;&nbsp; &nbsp;}&nbsp;&nbsp; &nbsp;for(i=1;i&lt;=n;i++){/*media de peso dos homens*/&nbsp;&nbsp; &nbsp;if(sexo[i]==1){&nbsp;&nbsp; &nbsp;total_peso=total_peso+peso[i];&nbsp;&nbsp; &nbsp;m++;&nbsp;&nbsp; &nbsp;}&nbsp;&nbsp; &nbsp;}&nbsp;&nbsp; &nbsp;if(m&gt;0){&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;printf("\nA media dos pesos dos homens eh %.1f ",total_peso/m);&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}else{&nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;printf("\nNao tem homens");&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}&nbsp;&nbsp;&nbsp; &nbsp;for(i=1;i&lt;=n;i++){&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if(sexo[i]==2){//verifica o sexo&nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;tidade=tidade+idade[i];//soma as idades se for do sexo feminino&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; s++;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; i=0;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for(i=1;i&lt;=n;i++){&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if((sexo[i]==2)&amp;&amp;(idade[i]&gt;25)){//se a idade na posição do SE anterior for maior que 25 midade implementa +1&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;midade++;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}&nbsp;&nbsp; &nbsp; if(s&gt;0){&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;printf("\nA média das idades das mulheres %.1f ",tidade/s);&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}else{&nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;printf("\nNao tem Mulheres");&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if(midade&gt;0){&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; printf("\nA quantidade de mulheres acima de 25 anos cerca de %d ",midade);&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}else{&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;printf("\nNao foram digitados mulheres acima de 25 anos");&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}&nbsp;&nbsp; &nbsp; getch();&nbsp;&nbsp; &nbsp;}
--------------------------------------------------------------------------------------------------------------------------------------------------------------------
&nbsp;&nbsp; //8) Fazer um programa para calcular a soma dos N primeiros números, onde N é lido.&nbsp;&nbsp; //Ex.: N=5. Soma = 1+2+3+4+5&nbsp;&nbsp; &nbsp;#include&lt;stdio.h&gt;&nbsp;&nbsp; &nbsp;#include&lt;conio.h&gt;&nbsp;&nbsp; &nbsp;main ()&nbsp;&nbsp; &nbsp;{&nbsp;&nbsp; &nbsp;int soma,x,num;&nbsp;&nbsp; &nbsp;printf("Escolha um numero :");&nbsp;&nbsp; &nbsp;scanf("%d",&amp;num);&nbsp;&nbsp; &nbsp;soma=0;&nbsp;&nbsp; &nbsp;for(x=0;x&lt;=num;x++){&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; soma=soma+x;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; printf(" + %d ",x);&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; printf("= %d",soma);&nbsp;&nbsp; &nbsp;getch();&nbsp;&nbsp; &nbsp;}