মূল বিষয়বস্তুতে যান

Let x be an integer which can take a value of 0 or 1. The statement if (x == 0) x =1 ; else x =0 ; is equivalent to which one of the following ?

সঠিক উত্তর

x =1 -x ;

সঠিক উত্তর: x =1 -x ;

এবার দেখা যাক এই প্রশ্নের উত্তরটা দিতে পারেন কিনা।

ভুল বা সঠিক হলে সাথে সাথেই ব্যাখ্যা সহ উত্তর দেখতে পারবেন।

আই সি টি ১ নম্বর

কোন মাধ্যমে আলোর পালস ব্যবহৃত হয়?

আই সি টি বিষয়ে ১০ টি গুরুত্বপূর্ণ প্রশ্ন

১০ মার্কের MCQ কুইজ

বিস্তারিত ব্যাখ্যা

এই প্রশ্নের বিশেষজ্ঞ বিশ্লেষণ

Let x be an integer which can take a value of 0 or 1. The statement <code>if (x == 0) x =1 ; else x =0 ;</code> is equivalent to which one of the following?

  1. x = 1 + x;

  2. x = x - 1;

  3. x = 1 - x;

  4. x = 1 % x;

The correct answer is: x = 1 - x;

To understand why the statement <code>x = 1 - x;</code> is equivalent to <code>if (x == 0) x = 1; else x = 0;</code>, consider the logical flow of the given if-else statement:

  • When <code>x == 0</code>: The statement <code>x = 1;</code> is executed.

  • When <code>x == 1</code>: The statement <code>x = 0;</code> is executed.

Now, let's analyze each choice to see which one replicates this behavior:

  1. <code>x = 1 + x;</code> <br>This does the following:

    • If <code>x = 0</code>, then <code>x = 1 + 0 = 1</code>.

    • If <code>x = 1</code>, then <code>x = 1 + 1 = 2</code>.

    Therefore, it does not correctly replicate the behavior of the given if-else statement.

  2. <code>x = x - 1;</code> <br>This does the following:

    • If <code>x = 0</code>, then <code>x = 0 - 1 = -1</code>.

    • If <code>x = 1</code>, then <code>x = 1 - 1 = 0</code>.

    Again, this does not correctly replicate the behavior because <code>x</code> can become -1, which is not a valid outcome based on the original problem constraints (i.e., <code>x</code> can only be 0 or 1).

  3. <code>x = 1 - x;</code> <br>This does the following:

    • If <code>x = 0</code>, then <code>x = 1 - 0 = 1</code>.

    • If <code>x = 1</code>, then <code>x = 1 - 1 = 0</code>.

    Hence, this choice perfectly replicates the behavior of the given if-else statement.

  4. <code>x = 1 % x;</code> <br>This choice is problematic because it attempts to divide by zero when <code>x</code> is 0, which will result in a runtime error. Therefore, it is not a valid transformation of the given problem.

Therefore, upon examination of each choice, we conclude that the correct answer is: x = 1 - x;

সকল অপশন

রেফারেন্স মাত্র

  1. x = 1 +x ;
  2. x =x -1 ;
  3. x =1 -x ; সঠিক
  4. x = 1 % x;

প্রশ্ন তথ্য

বিষয়
আই সি টি
শ্রেণী
চাকুরী প্রস্তুতি - ব্যাংক
মার্ক
1.00

আই সি টি বিষয়ের আরও প্রশ্ন

  1. 1

    কোন মাধ্যমে আলোর পালস ব্যবহৃত হয়?

  2. 2কোন চিহ্নটি ই-মেইল ঠিকানায় অবশ্যই থাকবে?
  3. 3

    ১০১১১০ বাইনারি নাম্বারে সমতুল্য ডেসিমাল নাম্বার কোনটি?

  4. 4

    নিচের কোনটি multi-tasking operation system নয়?

  5. 5

    ‘Gitanjali’ of Rabindranath Tagore was translated by___

মেধাবী অ্যাপ

৪.৯ · বিনামূল্যে
ইনস্টল