Please tell the novice programmer what's wrong with the code. The error here is certainly not one. The compiler returns only zeros but the answers in the amount in which it is required. The essence of the program is as follows: the user sets the initial and final values ​​of X as well as the step of changing the variable, the program must pass x through two formulas and from the two results return the largest for each step.

#include <stdio.h> #include <math.h> #include <stdbool.h> #define NUM 108 double startX, deltaX, endX, x, f1, f2; double function1(){ f1 = log(1-NUM/sin(x)); return 0; } double function2(){ f2 = tan(x)/NUM; return 0; } double decideFUNC(){ for(x = startX; x <= endX; x += deltaX){ function1(); function2(); if(function1==function2) printf("max values are the same %f\n", function1); else{ if (function1>function2) printf("%f\n", f1); else printf("%f\n",f2); } } return 0; } int main(){ printf("Enter start value X: \n"); scanf("%d", &startX); printf("Enter delta X: \n"); scanf("%d", &deltaX); printf("Enter ending value X: \n"); scanf("%d", &endX); decideFUNC(); return 0; } 

Closed due to the fact that off-topic participants Kromster , freim , Suvitruf , LFC , aleksandr barakin January 27 at 16:00 .

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 . " - Kromster, freim, Suvitruf, LFC
If the question can be reformulated according to the rules set out in the certificate , edit it .

  • if(function1==function2) and if (function1>function2) - what is compared here? The compiler clearly pointed you to gross errors in these lines. Did you just ignore the compiler diagnostic messages? - AnT

2 answers 2

 #include <stdio.h> #define NUM 108 double startX, deltaX, endX; double function1(double x) { return log(1 - NUM / sin(x)); } double function2(double x) { return tan(x) / NUM; } double decideFUNC(){ double x, f1, f2; for(x = startX; x <= endX; x += deltaX) { f1 = function1(x); f2 = function2(x); if (f1 == f2) { // вряд ли мы сюда попадем printf("max values are the same %f\n", f1); } else { if (f1 > f2) printf("x = %f, f1 = %f (%f, %f)\n", x, f1, f1, f2); else printf("x = %f, f2 = %f (%f, %f)\n", x, f2, f1, f2); } } } int main() { startX = 40; deltaX = 4; endX = 100; decideFUNC(); return 0; } 

 x = 40.000000, f2 = -0.010345 (nan, -0.010345) x = 44.000000, f2 = 0.000164 (nan, 0.000164) x = 48.000000, f1 = 4.952854 (4.952854, 0.011112) x = 52.000000, f2 = -0.056049 (nan, -0.056049) x = 56.000000, f1 = 5.337897 (5.337897, -0.005660) x = 60.000000, f1 = 5.873014 (5.873014, 0.002963) x = 64.000000, f2 = 0.021739 (nan, 0.021739) x = 68.000000, f1 = 4.798077 (4.798077, -0.018890) x = 72.000000, f2 = -0.002430 (nan, -0.002430) x = 76.000000, f2 = 0.006359 (nan, 0.006359) x = 80.000000, f1 = 4.697422 (4.697422, 0.083367) x = 84.000000, f2 = -0.009983 (nan, -0.009983) x = 88.000000, f2 = 0.000328 (nan, 0.000328) x = 92.000000, f1 = 4.938469 (4.938469, 0.011521) x = 96.000000, f2 = -0.050475 (nan, -0.050475) x = 100.000000, f1 = 5.367305 (5.367305, -0.005437) 

https://onlinegdb.com/SkwGxSI7E

  • Igor, unfortunately all the same does not work. Console display only Microsoft Windows [Version 6.1.7601] (c) Microsoft Corporation 2009. All rights reserved. C: \ Users \ Dad> cd ../../c C: \ C> gcc test.c -o test C: \ C> test Enter start value X: 40 Enter delta X: 4 Enter ending value X: 100 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 C: \ C> - Sergey
  • And if instead of #define NUM 108 write #define NUM 108f ? (So ​​say, wild guess). - Yaant
  • one
    @ Sergey You inaccurately copied my code to yourself. - Igor
  1. Each of the two functions returns 0, and returns to nowhere.
  2. In if-ah it is not clear what is being compared.

First you need to deal with these two points.