The code works, but incorrectly, I can not understand what the error is. Here is the task: Let x0 = a; xk = qx(k–1) + b , ( k = 1, 2, ...) x0 = a; xk = qx(k–1) + b , ( k = 1, 2, ...) . Given a non-negative integer n , real a , b , c , d , q ( c < d ). Does xn belong to the interval ( c , d )?

Code:

 #include<stdafx.h> #include<math.h> #include<cstdlib> #include<iostream> int main() { setlocale(LC_ALL, "Russian"); int n, k; float a, b, c, d, q; float x[100]; { printf("Введіть значення n: "); scanf_s("%lf", &n); printf("Введіть значення a,b,c,d,q: \n"); scanf_s("%i ", &a, &b, &c, &d, &q); x[0] = a; printf("x[0]= %5.1f\n", a); if (c > d); { printf("По умові c<d, введіть інші значення\n"); } if (c < d); for (k = 1; k <= 8; k++) { x[k] = q*x[(k - 1)] + b; scanf_s("x[%3f]= %5f", k, x[k]); } if ((c <= x[n]) && (d >= x[n])); printf("Хn належить інтервалу (c,d)"); else { printf("Хn не належить інтервалу (c,d)"); } } } 

Closed due to the fact that off-topic participants cheops , aleksandr barakin , D-side , Streletz , Vartlok 19 May '16 at 19:54 .

It seems that this question does not correspond to the subject of the site. Those who voted to close it indicated the following reason:

  • “Questions asking for help with debugging (“ why does this code not work? ”) Should include the desired behavior, a specific problem or error, and a minimum code for playing it right in the question . Questions without an explicit description of the problem are useless for other visitors. See How to create minimal, self-sufficient and reproducible example . " - cheops, aleksandr barakin, D-side, Streletz, Vartlok
If the question can be reformulated according to the rules set out in the certificate , edit it .

    1 answer 1

    Your code is sick with all childhood diseases - incorrect format specifiers, a semicolon after an if , and even the header file is connected incorrectly ... In a word, it doesn’t work for you - it should not be compiled :)

    Here is the correct version, see, compare, understand what and why is not like you ...

     #include<stdio.h> int main() { setlocale(LC_ALL, "Russian"); int n, k; float a, b, c, d, q; float x[100]; { printf("Введiть значення n: "); scanf_s("%d", &n); printf("Введiть значення a,b,c,d,q: \n"); scanf_s("%f %f %f %f %f", &a, &b, &c, &d, &q); x[0] = a; printf("x[0]= %5.3f\n", a); if (c >= d); { printf("По умовi c<d, введiть iншi значення\n"); } for (k = 1; k <= 8; k++) { x[k] = q * x[k - 1] + b; printf("x[%d]= %5.3f\n", k, x[k]); } if ((c <= x[n]) && (d >= x[n])) { printf("Хn належить iнтервалу (c,d)\n"); } else { printf("Хn не належить iнтервалу (c,d)\n"); } } }