Count all possible N digit numbers that satisfy the given condition in C++

C++Server Side ProgrammingProgramming

C in Depth: The Complete C Programming Guide for Beginners

45 Lectures 4.5 hours

Practical C++: Learn C++ Basics Step by Step

Most Popular

50 Lectures 4.5 hours

Master C and Embedded C Programming- Learn as you go

66 Lectures 5.5 hours

In this tutorial, we will be discussing a program to find the number of possible N digit numbers that satisfy the given condition.

For this we will be provided with an integer. Our task is to check which one of number having N digits follow

Number + Reverse(Number) = 10N -1

Example

#include <bits/stdc++.h>
using namespace std;
//returning the count of numbers
string count_num(int N){
if (N % 2 == 1)
return 0;
string result = "9";
for (int i = 1; i <= N / 2 - 1; i++)
result += "0";
return result;
}
int main(){
int N = 4;
cout << count_num(N);
return 0;
}

Output

90
Updated on 10-Feb-2020 12:02:03