Algorithms | Analysis of Algorithms | Question 19 Last Updated : 21 Aug, 2025 Comments Improve Suggest changes 5 Likes Like Report Consider the following program fragment for reversing the digits in a given integer to obtain a new integer. Let n = D1D2…Dm C int n, rev; rev = 0; while (n > 0) { rev = rev*10 + n%10; n = n/10; } The loop invariant condition at the end of the ith iteration is: (GATE CS 2004) (A) n = D1D2….Dm-i and rev = DmDm-1…Dm-i+1 (B) n = Dm-i+1…Dm-1Dm and rev = Dm-1….D2D1 (C) n != rev (D) n = D1D2….Dm and rev = DmDm-1…D2D1 Answer: (A) Explanation: We can get it by taking an example like n = 54321. After 2 iterations, rev would be 12 and n would be 543.Quiz of this Question Create Quiz Comment K kartik Follow 5 Improve K kartik Follow 5 Improve Article Tags : DSA Algorithms-Analysis of Algorithms Analysis of Algorithms Explore DSA FundamentalsLogic Building Problems 2 min read Analysis of Algorithms 1 min read Data StructuresArray Data Structure 3 min read String in Data Structure 2 min read Hashing in Data Structure 2 min read Linked List Data Structure 3 min read Stack Data Structure 2 min read Queue Data Structure 2 min read Tree Data Structure 2 min read Graph Data Structure 3 min read Trie Data Structure 15+ min read AlgorithmsSearching Algorithms 2 min read Sorting Algorithms 3 min read Introduction to Recursion 15 min read Greedy Algorithms 3 min read Graph Algorithms 3 min read Dynamic Programming or DP 3 min read Bitwise Algorithms 4 min read AdvancedSegment Tree 2 min read Binary Indexed Tree or Fenwick Tree 15 min read Square Root (Sqrt) Decomposition Algorithm 15+ min read Binary Lifting 15+ min read Geometry 2 min read Interview PreparationInterview Corner 3 min read GfG160 3 min read Practice ProblemGeeksforGeeks Practice - Leading Online Coding Platform 1 min read Problem of The Day - Develop the Habit of Coding 5 min read Like