View Code of Problem 104

#include<stdio.h>

int main()
{
    int n,v1,v2,t;
    float s;
    while(scanf("%d%d%d%d",&n,&v1,&v2,&t) != EOF)
    {
        if(v1 <= 0 && v2 >= 0 && n > 0)
            printf("%NO\n");
        if(v1 <= 0 && v2 <= 0)
        {
            if((-v2)*t - (-v1)*t >= n*1000)
            {
                s = (n*1000) / (v1-v2);
                printf("%.2f\n",s);
            }
            else
                printf("NO\n");
        }
        if(v1 > 0 && v2 < 0)
        {
            s = (n*1000) / (v1-v2);
            printf("%.2f\n",s);
        }
        else
        {
            if(v2*t - v1*t >= n*1000)
            {
                s = (n*1000) / (v2-v1);
                printf("%.2f\n",s);
            }
            else
                printf("NO\n");
        }
    }

}

Double click to view unformatted code.


Back to problem 104