sem precisar alterar tamanho do vetor toda hora
#include <iostream>
using namespace std;
int main() {
int vetor[7], i;
vetor[0]=10;
vetor[1]=20;
vetor[2]=30;
vetor[3]=40;
vetor[4]=50;
vetor[5]=60;
vetor[6]=70;
for(i=0;i<sizeof(vetor)/4;i++)
{
cout << vetor[i] <<endl;
}
return 0;
}
----------------------------------------------------------------------------------------------------------
ou
#include <iostream>
using namespace std;
int main() {
int tam = 7;
int vetor[tam], i;
vetor[0]=10;
vetor[1]=20;
vetor[2]=30;
vetor[3]=40;
vetor[4]=50;
vetor[5]=60;
vetor[6]=70;
for(i=0;i<tam;i++)
{
cout << vetor[i] <<endl;
}
return 0;
}
--------------------------------------------------------------------------------------------------------------------
ou
#include <iostream>
using namespace std;
int main() {
int vetor[7]={10,20,30,40,50,60,70}, i;
for(i=0;i<7;i++)
{
cout << vetor[i] <<endl;
}
return 0;
}
----------------------------------------------------------------------------------------------------------------------------
#include <iostream>
using namespace std;
int main() {
int vetor[7]={10,20,30,40,50,60,70}, i;
for(i=0;i<sizeof(vetor)/4;i++)
{
cout << vetor[i] <<endl;
}
return 0;
}
Matemática Pura, Matemática Aplicada, Computação, educação matemática, teoria dos números, programação e desenvolvimento de jogos. - Matheus Nakade - @MorgaoFreud
quarta-feira, 6 de novembro de 2019
vetor 1 basico
#include <iostream>
using namespace std;
int main() {
int vetor[5], i;
vetor[0]=10;
vetor[1]=20;
vetor[2]=30;
vetor[3]=40;
vetor[4]=50;
for(i=0;i<5;i++)
{
cout << vetor[i] <<endl;
}
return 0;
}
using namespace std;
int main() {
int vetor[5], i;
vetor[0]=10;
vetor[1]=20;
vetor[2]=30;
vetor[3]=40;
vetor[4]=50;
for(i=0;i<5;i++)
{
cout << vetor[i] <<endl;
}
return 0;
}
vetor // array padrao
tipo_do_vetor nome_do_vetor[_tamanho_do_vetor]
exemplo
int carro[5];
------------------
int cor1, cor 2, cor 3;
ou
int cor[3];
vetor sempre comeca no valor 0
#include <iostream>
using namespace std;
int main() {
int vetor[5];
vetor[0]=10;
vetor[1]=20;
vetor[2]=30;
vetor[3]=40;
vetor[4]=50;
cout<< vetor[0] << endl;
return 0;
}
exemplo
int carro[5];
------------------
int cor1, cor 2, cor 3;
ou
int cor[3];
vetor sempre comeca no valor 0
#include <iostream>
using namespace std;
int main() {
int vetor[5];
vetor[0]=10;
vetor[1]=20;
vetor[2]=30;
vetor[3]=40;
vetor[4]=50;
cout<< vetor[0] << endl;
return 0;
}
for 4 sem comandos apenas para demorar um tempo
#include <iostream>
using namespace std;
int main() {
int x, y, z;
// inscrementando 2 variaveis em 1 for
for(int tmp=0;tmp<1000000000;tmp++);
for(x=0;x<10;x++)
{
cout<<x<<endl;
}
return 0;
}
using namespace std;
int main() {
int x, y, z;
// inscrementando 2 variaveis em 1 for
for(int tmp=0;tmp<1000000000;tmp++);
for(x=0;x<10;x++)
{
cout<<x<<endl;
}
return 0;
}
for 3 condicional composta de mais de um parametro
#include <iostream>
using namespace std;
int main() {
int x, y, z;
// inscrementando 2 variaveis em 1 for
for(x=0, y=1, z=0;x<10 && z<=6; x++, y+=2, z+=2)
{
cout<<x<< " // "<<y<<" // "<<z<<endl;
}
return 0;
}
using namespace std;
int main() {
int x, y, z;
// inscrementando 2 variaveis em 1 for
for(x=0, y=1, z=0;x<10 && z<=6; x++, y+=2, z+=2)
{
cout<<x<< " // "<<y<<" // "<<z<<endl;
}
return 0;
}
Assinar:
Comentários (Atom)