Jump to content

Duvida acerca de arrays


Floating
 Share

Recommended Posts

Boas. Estou a tentar criar um programa com arrays, onde eu vou usar a array de acordo com uma quantidade de numeros inserida pelo utilizador.

Por exemplo:

cout<<"Quantos numeros quer inserir";

cin>>qtddnum;

nums[0]=qtddnum;

Será algo assim? O indice da array deve armazenar a quantidade de numeros q o utilizador quererá inserir, só não tenho a certeza se estou a faze-lo correctamente e pela ordem correcta, e se deveria atribuir 0 ao array antes de lhe atribuir a quantidade de numeros.. Estou um pouco confuso, alguem me poderia ajudar?

Link to comment
Share on other sites

int *nums = new int[qtddnum];

“There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies, and the other way is to make it so complicated that there are no obvious deficiencies. The first method is far more difficult.”

-- Tony Hoare

Link to comment
Share on other sites

Não, vais criar espaço em memória suficiente para armazenar a quantidade de números.

“There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies, and the other way is to make it so complicated that there are no obvious deficiencies. The first method is far more difficult.”

-- Tony Hoare

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.