Number with even sum of digits | C ++ program to find n - th Good number . ; Function to find kth good number . ; Find the last digit of n . ; If last digit is between 0 to 4 then return 2 * n . ; If last digit is between 5 to 9 then return 2 * n + 1. ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; long long int findKthGoodNo ( long long int n ) { int lastDig = n % 10 ; if ( lastDig >= 0 && lastDig <= 4 ) return n << 1 ; else return ( n << 1 ) + 1 ; } int main ( ) { long long int n = 10 ; cout << findKthGoodNo ( n ) ; return 0 ; }