HackerRank C- Kangaroo



omplete the function kangaroo in the editor below. It should return YES if they reach the same position at the same time, or NO if they don't.

kangaroo has the following parameter(s):

x1, v1: integers, starting position and jump distance for kangaroo 1
x2, v2: integers, starting position and jump distance for kangaroo 2



  1. #include<stdio.h>
  2. int main()
  3. {
  4. int x1,x2,v1,v2;
  5. scanf("%d %d %d %d",&x1,&v1,&x2,&v2);
  6. if(x2>x1&&v2>v1){
  7. printf("NO");
  8. }
  9. else{
  10. for(int i=0;i<10000;i++){
  11. x1+=v1;
  12. x2+=v2;
  13. if(x1==x2){
  14. printf("YES");
  15. exit(0);
  16. }
  17. }
  18. printf("NO");
  19. }
  20. }

download android app