Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Why does this C program give me an missing integer from an For loop?

I am trying to get the value of "w" but when I do the For loop ,it only gives me 4 results:

Problem:
https://imgur.com/a/F9wPKF7

Code:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

#include <stdio.h>
#include <math.h>

int main() {
    int x,e,w;
    float a = 2.5;
    for (x=1; x<6; x++) {
        if (x>a) {
            w = x*cbrt(x-a);
        } 
        else if (x=a) {
            w = x*sin(a*x);
        }
        else if (x<a) {
            w = pow(e,(-a*x))*cos(a*x);
        } 
        printf("%d ",x);
    }

    return 0;
}

Output:

2 3 4 5 

I know in this program i dont search for the value of w but I wanted to see why does it give me only 4 number instead of 5? why is the one missing and ow can I solve it? Thank you

>Solution :

else if (x=a) should beelse if (x==a)

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading