Baixe o app para aproveitar ainda mais
Leia os materiais offline, sem usar a internet. Além de vários outros recursos!
Prévia do material em texto
Atividade 2. 1) #include <iostream> using namespace std; int main(){ int v[7],i,menor,pos=0; for(i=0;i<=6;i++){ cin>>v[i]; } menor=v[0]; for(i=0;i<=6;i++){ if(v[i]<menor){ menor=v[i]; pos=i+1; } } cout<<"O menor valor do vetor eh: "<<menor<<"\n"<<endl; cout<<"e sua posicao eh: "<<pos<<endl; system("pause"); } 2) #include <iostream> using namespace std; int main(){ int v1[10],v2[10],v3[10],i; for(i=0;i<=9;i++){ cin>>v1[i]; } for(i=0;i<=9;i++){ cin>>v2[i]; } for(i=0;i<=9;i++){ v3[i]=v1[i]*v2[i]; } for(i=0;i<=9;i++){ cout<<"Vetor resultante na posiao "<<i<<": "; cout<<v3[i]<<"\n"; } system("pause"); } 3) #include <iostream> using namespace std; int main(){ int v1[5],v2[5],v3[10],i; for(i=0;i<=4;i++){ cin>>v1[i]; } for(i=0;i<=4;i++){ cin>>v2[i]; } for(i=0;i<=4;i++){ v3[i]=v1[i]; v3[i+5]=v2[i]; } cout<<"V3= "; for(i=0;i<=9;i++){ cout<<v3[i]<<" "; } cout<<endl; system("pause"); } 4) #include <iostream> using namespace std; int main(){ int v[20],i; for(i=0;i<=19;i++){ cin>>v[i]; } cout<<"\n"; for(i=0;i<=18;i++){ for(int j=i+1;j<=19;j++){ int temp=v[i]; v[i]=v[j]; v[j]=temp; } } for(i=0;i<=19;i++){ cout<<v[i]<<" "; } system("pause"); } 5) #include <iostream> using namespace std; int main(){ int v[10],x,i; for(i=0;i<=9;i++){ cin>>v[i]; } cin>>x; for(i=0;i<=19;i++){ if(v[i]==x){ cout<<"Esta no vetor e na posicao: "<<i+1<<"\n"<<endl; } } system("pause"); } 6) #include <iostream> using namespace std; int main(){ char v[5]; int i,j; bool ePalindro=true; for(i=0;i<=4;i++){ cout<<"Digite uma letra: "; cin>>v[i]; } i=0; j=4; while(i<j && ePalindro){ if(v[i]==v[j]){ i++; j--; }else{ ePalindro=false; } } if(ePalindro){ cout<<"Eh palindromo\n"; }else{ cout<<"Nao eh palindromo\n"; } system("pause"); } 7) #include <iostream> using namespace std; int main(){ char v[20]; int i, vogais=0,consoantes=0; for(i=0;i<=19;i++){ cin>>v[i]; } for(i=0;i<=19;i++){ if((v[i]=='a') || (v[i]=='e') || (v[i]=='i') || (v[i]=='o') || (v[i]=='u')){ vogais++; } } consoantes=20-vogais; cout<<"Vogais: "<<vogais<<"\n"<<endl; cout<<"Consoantes: "<<consoantes<<"\n"<<endl; system("pause"); } 8) #include <iostream> using namespace std; int main(){ int v1[50],v2[50],i; for(i=0;i<=49;i++){ cin>>v1[i]; } for(i=0;i<=49;i++){ if(v1[i]>=10){ v2[i]=v1[i]/10; }else{ v2[i]=0; } } for(i=0;i<=49;i++){ cout<<"O cliente "<<i+1<<" tem "<<v2[i]<<" locacoes gratuitas!\n"; } cout<<endl; system("pause"); } 9) #include <iostream> using namespace std; int main(){ int v[13],i,r[13],x,j,y=1,cont=0; for(i=0;i<=12;i++){ cin>>v[i]; } cin>>x; for(i=1;i<=x;i++){ for(j=0;j<=12;j++){ cout<<"Informe a resposta do cartao "<<j+1<<" do apostador "<<i<<"\n"; cin>>r[i]; if(r[i]==v[i]){ cont++; } } cout<<"O apostador "<<y<<" acertou "<<cont<<"\n"; y++; cout<<"\n"; if(cont==13){ cout<<"GANHADOR\n"; }else{ cout<<"DEIXA PRA PROXIMA\n"; } cont=0; } system("pause"); } 10) #include <iostream> using namespace std; int main(){ char v[10],r[10]; int i,j,cont=0; for(i=0;i<=9;i++){ cin>>v[i]; } for(j=1;j<=20;j++){ for(i=0;i<=9;i++){ cout<<"Informe a resposta da questao "<<i+1<<" do aluno "<<j<<"\n"; cin>>r[i]; if(r[i]==v[i]){ cont++; } } cout<<"Aluno "<<j<<" teve "<<cont<<" acertos\n"; if(cont>=6){ cout<<"ALUNO APROVADO\n\n"; }else{ cout<<"ALUNO REPROVADO\n\n"; } cont=0; } system("pause"); } 11) #include <iostream> using namespace std; int main(){ int v[10],i,j; for(i=0;i<=9;i++){ cout<<"Informe a V["<<i+1<<"]: \n"; cin>>v[i]; } cout<<"\n"; for(i=0;i<=9;i++){ cout<<v[i]<<" "; } cout<<"\n"; for(i=0;i<=8;i++){ for(j=i+1;j<=9;j++){ if(v[i]<v[j]){ int temp=v[i]; v[i]=v[j]; v[j]=temp; } } } cout<<"\n"; for(i=0;i<=9;i++){ cout<<v[i]<<" "; } cout<<"\n"; system("pause"); } 12) #include <iostream> using namespace std; int main(){ int m[5][5],i,j,soma=0; for(i=0;i<=4;i++){ for(j=0;j<=4;j++){ cout<<"Informe a posicao "<<i+1<<" da coluna "<<j+1<<"\n"; cin>>m[i][j]; } } for(i=0;i<=4;i++){ for(j=0;j<=4;j++){ cout<<m[i][j]<<" "; } cout<<"\n"; } cout<<"\n"; for(i=0;i<=4;i++){ soma=0; for(j=0;j<=4;j++){ soma+=m[i][j]; } cout<<"A soma da linda "<<i+1<<" eh: "<<soma<<"\n"<<endl; } system("pause"); } 13) #include <iostream> using namespace std; int main(){ int m[6][6],i,j; for(i=0;i<=5;i++){ for(j=0;j<=5;j++){ cout<<"Informe a posicao "<<i+1<<" da coluna "<<j+1<<"\n"; cin>>m[i][j]; } } for(i=0;i<=5;i++){ for(j=0;j<=5;j++){ cout<<m[i][j]<<" "; } cout<<"\n"; } for(j=0;j<=5;j++){ int temp=m[1][j]; m[1][j]=m[5][j]; m[5][j]=temp; } cout<<"\n"; for(i=0;i<=5;i++){ for(j=0;j<=5;j++){ cout<<m[i][j]<<" "; } cout<<"\n"; } cout<<"\n"; for(j=0;j<=5;j++){ int temp=m[j][0]; m[j][0]=m[j][3]; m[j][3]=temp; } cout<<"\n"; for(i=0;i<=5;i++){ for(j=0;j<=5;j++){ cout<<m[i][j]<<" "; } cout<<"\n"; } cout<<"\n"; for(i=0;i<=5;i++){ m[i][i]=0; } for(i=0;i<=5;i++){ for(j=0;j<=5;j++){ cout<<m[i][j]<<" "; } cout<<"\n"; } cout<<"\n"; system("pause"); } 14) #include <iostream> using namespace std; int main(){ float m[10][3],media,maior,soma=0; int i,j; for(i=0;i<=9;i++){ for(j=0;j<=2;j++){ cout<<"Informe a nota "<<j+1<<" do aluno "<<i+1<<"\n"; cin>>m[i][j]; } } maior=m[0][0]; for(i=0;i<=9;i++){ soma=0; for(j=0;j<=2;j++){ soma+=m[i][j]; } media=soma/3; cout<<"A media do aluno "<<i+1<<" eh: "<<media<<"\n"<<endl; if(media>=7){ cout<<"ALUNO APROVADO\n\n\n"; }else{ cout<<"ALUNO REPROVADO\n\n\n"; } if(m[i][j]>maior){maior=m[i][j]; } } cout<<"A maior media eh: "<<maior<<"\n"<<endl; system("pause"); } 15) #include <iostream> using namespace std; int main(){ int m[8][5], i,j; float valorMesa, valorTotal=0, p[5]; for(i=0;i<=7;i++){ for(j=0;j<=4;j++){ cout<<"Digite a quantidade de pratos P "<<j<<" da mesa "<<i<<"\n"; cin>>m[i][j]; } } p[0]=5;p[1]=6.3;p[2]=7.2;p[3]=8.7;p[4]=9.6; for(i=0;i<=7;i++){ valorMesa=0; for(j=0;j<=4;j++){ valorMesa+=p[j]*m[i][j]; } cout<<"Valor da mesa "<<i<<"="<<valorMesa<<endl; valorTotal+=valorMesa; } cout<<"Valor total= "<<valorTotal<<endl; system("pause"); }
Compartilhar