- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

# Maximum number that can be display on Seven Segment Display using N segments in C++

Given the task is to find the maximum number that can be displayed using N segment on ant number of seven segment display.

Let’s now understand what we have to do using an example −

**Input** − N=5

**Output** − 71

**Explanation** − The largest number will be displayed as follows on the seven segment display −

**Input** − N=6

**Output** − 111

## Approach used in the below program as follows

The following situation can be divided into 3 case −

**Case 1**−If N is 0 or 1, then it is not possible to display any number.

**Case 2**−If N is odd. Then the numbers that can be displayed with odd number of segments are 2, 3, 5, 7 and 8 out of which 7 takes the least number of segments, that is, 3. Therefore 7 is the most significant digit in this case.

**Case 3**−If N is even. Then the numbers that can be displayed with odd number of segments are 0, 1, 4, 6, 9 and 8 out of which 1 takes the least number of segments, that is, 2. Therefore 1 is the most significant digit in this case.

In function MaxNumber() first check for the base condition using

if (N == 1 || N == 0)

Then using another if statement, check if N is even. If so then print “1” as it is the most significant digit in the even case and call MaxNumber(N - 2) as 2 segments are being used here.

Use another if statement to check if N is odd. If so then print “7” as it is the most significant digit in the odd case and call MaxNumber(N - 3) as 3 segments are being used here.

## Example

#include <iostream> using namespace std; void MaxNumber(int N){ //Condition to check base case if (N == 1 || N == 0){ return; } //If the number is even if (N % 2 == 0){ cout << "1"; MaxNumber(N - 2); } //If the number is odd else if (N % 2 == 1){ cout << "7"; MaxNumber(N - 3); } } //Main function int main(){ int N; N = 5; MaxNumber(N); return 0; }

## Output

If we run the above code we will get the following output −

71

- Related Questions & Answers
- Interfacing 7(Seven) Segment Display to 8085 Microprocessor
- Check if number can be displayed using seven segment led in Python
- Seven Segment Displays
- Maximum bishops that can be placed on N*N chessboard in C++
- Maximum number of parallelograms that can be made using the given length of line segments in C++
- Maximum number of segments that can contain the given points in C++
- Maximum Number of Events That Can Be Attended in C++
- Maximum number of candies that can be bought in C
- Find maximum number that can be formed using digits of a given number in C++
- Maximum litres of water that can be bought with N Rupees in C++
- Maximum number of people that can be killed with strength P in C++
- Maximum number of threads that can be created within a process in C
- How to display a line in segment of a plot using ggplot2 in R?
- Program to find maximum units that can be put on a truck in Python
- Check if mirror image of a number is same if displayed in seven segment displays in Python