9th Class Computers Science Programming Concepts Question Bank Algorithms and Flowcharts in Programming

  • question_answer
    Given here is an algorithm to swap two numbers. Which of the following line will replace "?" to complete the algorithm?
    Step 1: Read two numbers X and Y.
    Step 2: ?
    Step 3: Y = X - Y
    Step 4: X = X - Y
     

    A) \[X=X+Y\]

    B) \[X=X\times Y\]

    C) \[X=X/Y\]

    D) \[X=X-Y\]

    Correct Answer: A

    Solution :

    Suppose value of X =10 and Y=20 X=X+Y\[\to\]X= 10+20=30 Y= X - Y\[\to\]Y= 30-20=10 X=X-Y\[\to\]X=30-10=20 Now X= 20 and Y= 10


You need to login to perform this action.
You will be redirected in 3 sec spinner