View Code of Problem 104

#include <stdio.h>
#include <math.h>
int main(){
  int n,v1,v2,t;
  float t1,t2,t3;
  while (scanf("%d%d%d%d",&n,&v1,&v2,&t) != EOF){
    if(v1<0&&v2>0)
      printf("NO\n");
    else if(v1>0&&v2<0){
      t1=(float)((n*1000)/(fabs(v2)+v1));
      if(t1>t)
        printf("NO\n");
        else
          printf("%.2f",t1);
        
        
        
      
    }
    else if(v1>0&&v2>0){
      if(v1<=v2)
        printf("NO\n");
      else{
        t2=(float)((n*1000)/(v1-v2));
        if(t2>t)
          printf("NO\n");
        else
          printf("%.2f",t2);
        
        
        
        
      
      }
    
    
    }
    else if(v1<0&&v2<0){
      if(fabs(v1)>=fabs(v2))
        printf("NO\n");
      else{
        t3=(float)((n*1000)/(fabs(v2)-fabs(v1)));
        if(t3>t)
          printf("NO\n");
        else
          printf("%.2f",t3);
      
      }
    
    
    
    }
  
  
  }

return 0;
}

Double click to view unformatted code.


Back to problem 104