I have a list of number : -1.5 , – 1 , -0,5 , … , 100.
I want to assign them to an array.
E.g :
a[0] = -1.5;
a[1] = -1;
....
a[202] = 100;
Can you show me how to do it ?
Thanks.
>Solution :
If you want to initialize array with several values, you can use this:
int a[4] = {1, 2, 3, 4};
But it should not be used, if you have a lot of numbers. If you need to assign list of numbers, that you stated in question, you should describe them with mathmetical expression in cycle:
for(int i = 0; i < 203; i++)
{
a[i] = -1.5 + 0.5 * i;
}
If you want to assign array with list of values, that can’t be described with mathematical expression, you should read them from file.