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. }
Please click on the like button if it worked

Solution not working or have any suggestions? Please send an email to [email protected]

donate a cup of tea :)

Join Our Facebook Group

Share this solution


Codesadda.com is your home of programming solutions, tutorials, video tutorials and much more. Sign Up for our weekly newsletter to get update about new content.

Like us on Facebook | Connect with us on LinkedIn | Subscribe our Channel on Youtube