#include <stdio.h> #include <stdlib.h> void main() { int i; float ost, a[6], b[6]; for (i = 0; i < 7; i++) { printf("A[%i] = ", a[i]); scanf("%f", a[i]); } for (i = 0; i < 7; i++) { ost = a[i] % 2; if (ost == 1) { b[i] = ln(i + 1.5) * -1; } else { b[i] = ln(i + 1.5); } } } - Thanks, but it still does not work correctly (sizeof (a) has not yet used it), the program displays A [0] = everywhere! And sorts wrong. - Alexandr
- Assignment at least voiced. - Hedgehog
|
2 answers
When indexing arrays it is better to use the sizeof operator:
for (int i = 0; i < sizeof(a) / sizeof(a[0]); i++) { } When you call the scanf function, you need to pass the address of the variable to which you want to write:
scanf("%f", &a[i]); The modulo% operator applies to integers:
ost = (int)a[i] % 2; |
I'm a mind reader! Replace all 7 with 6! And throw out the code. :)
- Thanks, and in the line ost = a [i]% 2; ??? - Alexandr
- In the line ost = a [i]% 2; you need to change the type of operands. For example, like this: ost = (int) a [i]% 2; - Nicolas Chabanovsky ♦
- If you want to display: A [0] =, A [1] =, then do this: printf ("A [% i] =", i); - Hedgehog
|