Answer the question
In order to leave comments, you need to log in
What's wrong with #define?
There are 100 elements in the array, all elements are initially zero. You need to make them start changing their value to 1 or 0 in a certain order:
1. Change the value of all elements of the array to 1.
2. Change the value of every second element in the array.
3. change the value of every third element in the array.
4. Do action 1-3 97 more times.
5. Find all 1s in the array and display their index on the screen.
I took the task from here
and everything would be fine, things were done and bloomed, but as I decided to start I got it
. It doesn’t matter if I commented on all printfs or not, I always got this on the exhaust. What is the reason for this, and why does it not work as it should?
ps For the sake of completeness, I will say that I understand define as a thing that simply substitutes some value instead of a human word.
pps so that there are no questions, the source was saved and compiled again.
#include <stdio.h>
#define OPEN 1
#define CLOSE 0
void switch_state(int *status)
{
if(*status == CLOSE)
{
*status = OPEN;
//printf("OPEN");
}
else
{
*status = CLOSE;
//printf("CLOSE");
}
}
int main()
{
int state[100] = {CLOSE};
int i = 0;
while (i != 100)
{
if (i % 2 == 0)
switch_state(&state[i]);
else if(i % 3 == 0)
switch_state(&state[i]);
else
{
switch_state(&state[i]);
//printf("%i\n", state[i]);
}
i++;
}
return 0;
}
Answer the question
In order to leave comments, you need to log in
function compareCalories(colaA, colaB) {
if (colaA.name > colaB.name) {
return 1;
} else if (colaA.name === colaB.name) {
// . . .
The task itself is strange.
Do action 1-3 97 more times.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question