On their way down the river, Jojo and Lili saw two frogs each in position X1 and X2. The two frogs were seen jumping happily towards the same direction, which was to come to Jojo. After watching the two frogs, Jojo and Lili saw that the speed of the two frogs was different. The first frog that starts jumping from position X1 has a speed of v1, while the second frog that starts jumping from position X2 has a speed of V2. Jojo guessed that "YES" the two frogs would be in the same position in a certain time T, while Bibi guessed "NO" that the two frogs would never be in the same position in that time. Help Jojo and Lili calculate the frog's movements to determine if their guess is correct. Format Input The first line of input consists of a series of integers namely X1, V1, X2, V2, T. X1 and V1 are the initial position and jump speed per second of the first frog. X2 and V2 are the initial position and jump speed per second of the second frog. Tis the second when the frog jumps. Format Output A string "YES" or “NO" Constraints 1ST < 10* 0SX1, X2 5 10* 1sV,V2 5 10* Sample Input 0 3 4 2 10 Sample Output YA Sample Input 0 3 4 2 3 Sample Output TIDAK In the sample above, let's say that frogs A and B start jumping together. Frog A starts jumping from position 0 at a speed of 3 per second. Then frog A's position per second: 3, 6, 9, 12, 15,...etc. Frog B starts jumping from position 4 at a rate of 2 per second. Then the position of frog B per second: 6, 8, 10, 12, 14,.etc. Within 3 seconds, the two frogs will NOT be in the same position. Both frogs can be in the same position in the fourth second, namely in position 12. So within 10 seconds the output is YES while in 3 seconds the output is NO.

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

Input And Output Must Be the same

write in c language

On their way down the river, Jojo and Lili saw two frogs each in position X1
and X2. The two frogs were seen jumping happily towards the same direction, which was to come to
Jojo. After watching the two frogs, Jojo and Lili saw that the speed of the two frogs was different. The
first frog that starts jumping from position X1 has a speed of v1, while the second frog that starts
jumping from position X2 has a speed of V2. Jojo guessed that "YES" the two frogs would be in the
same position in a certain time T, while Bibi guessed "NO" that the two frogs would never be in the
same position in that time. Help Jojo and Lili calculate the frog's movements to determine if their guess
is correct.
Format Input
The first line of input consists of a series of integers namely X1, V1, X2, V2, T.
X1 and V1 are the initial position and jump speed per second of the first frog.
X2 and V2 are the initial position and jump speed per second of the second
frog.
Tis the second when the frog jumps.
Format Output
A string “YES" or “NO"
Constraints
1ST< 10*
O< X1, X2< 10*
1<V1,V½ < 10*
Sample Input
0 3 4 2 10
Sample Output
YA
Sample Input
0 3 4 2 3
Sample Output
TIDAK
In the sample above, let's say that frogs A and B start jumping together.
Frog A starts jumping from position 0 at a speed of 3 per second.
Then frog A's position per second: 3, 6, 9, 12, 15,.etc.
Frog B starts jumping from position 4 at a rate of 2 per second.
Then the position of frog B per second: 6, 8, 10, 12,14,.etc.
Within 3 seconds, the two frogs will NOT be in the same position. Both frogs can be in the same
position in the fourth second, namely in position 12. So within 10 seconds the output is YES while in 3
seconds the output is NO.
Notes
Although it wasn't stated in the problem, you should now know that extra spaces or lines are
considered WRONG ANSWER.
Transcribed Image Text:On their way down the river, Jojo and Lili saw two frogs each in position X1 and X2. The two frogs were seen jumping happily towards the same direction, which was to come to Jojo. After watching the two frogs, Jojo and Lili saw that the speed of the two frogs was different. The first frog that starts jumping from position X1 has a speed of v1, while the second frog that starts jumping from position X2 has a speed of V2. Jojo guessed that "YES" the two frogs would be in the same position in a certain time T, while Bibi guessed "NO" that the two frogs would never be in the same position in that time. Help Jojo and Lili calculate the frog's movements to determine if their guess is correct. Format Input The first line of input consists of a series of integers namely X1, V1, X2, V2, T. X1 and V1 are the initial position and jump speed per second of the first frog. X2 and V2 are the initial position and jump speed per second of the second frog. Tis the second when the frog jumps. Format Output A string “YES" or “NO" Constraints 1ST< 10* O< X1, X2< 10* 1<V1,V½ < 10* Sample Input 0 3 4 2 10 Sample Output YA Sample Input 0 3 4 2 3 Sample Output TIDAK In the sample above, let's say that frogs A and B start jumping together. Frog A starts jumping from position 0 at a speed of 3 per second. Then frog A's position per second: 3, 6, 9, 12, 15,.etc. Frog B starts jumping from position 4 at a rate of 2 per second. Then the position of frog B per second: 6, 8, 10, 12,14,.etc. Within 3 seconds, the two frogs will NOT be in the same position. Both frogs can be in the same position in the fourth second, namely in position 12. So within 10 seconds the output is YES while in 3 seconds the output is NO. Notes Although it wasn't stated in the problem, you should now know that extra spaces or lines are considered WRONG ANSWER.
Expert Solution
Step 1

The code in C along with the comments for the requirements as per mentioned above is as follows:

#include <stdio.h>
int main()
{
    int x1, v1, x2, v2, t;
    scanf("%d %d %d %d %d", &x1, &v1, &x2, &v2, &t);
    int i = 0;
    //Flag variable to keep a check of same position
    int flag = 0;
    //Initialize the first position of both frogs with x1 and x2
    int dist1 = x1;
    int dist2 = x2;
    //Run the loop till the end of the given time interval
    for(i = 0; i < t; i++){
      //Increment whichever position is less amongst the two frog
      if(dist1 < dist2){
        dist1 += v1;
      }
      else if(dist2 < dist1){
        dist2 += v2;
      }
      //Check for equality of positions of the two frogs
      //If equal the make flag = 1 and break from the for loop
      else{
        flag = 1;
        break;
      }
    }
    //Check the value of flag and print the answer
    if(flag == 1){
      printf("YES");
    }
    else{
      printf("NO");
    }
    return 0;
}

steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY