c - How would I make an array of all the integers between 0 and 1000? -


not finding anywhere online google... , i'm not typing out numbers 1 one either because there has easier way!

int myfunction(void) {          //numbers = ??????;         int sum = 0;         for(int = 0; < sizeof(numbers); i++) {                 int currentnumber = numbers[i];                 if (currentnumber % 3 == 0 || currentnumber % 5 == 0) {                         sum = sum + currentnumber;                       }                }                printf("%d", sum); }     

update

someone in comments made point setting condition of loop, i'm still curious how 1 make array of integers [0,1,2,3,4..1000]

i'm not sure makes sense create array 1-1000, if going numbers[i], given numbers[i] == i. using single integer i, can save wasting space. if there motivation other have posted, can following:

int numbers[1001]; for(int = 0; <= 1000; i++)   numbers[i] = i; 

Comments

Popular posts from this blog

PHP DOM loadHTML() method unusual warning -

python - How to create jsonb index using GIN on SQLAlchemy? -

c# - TransactionScope not rolling back although no complete() is called -