---
title: "Write a program that take N integer number as input and display the second largest value."  
description: "Write a program that take N integer number as input and display the second largest value."  
author: "Mukul Goenka"  
published: 2021-11-07  
updated: 2021-11-07  
canonical: https://www.mindstick.com/forum/156802/write-a-program-that-take-n-integer-number-as-input-and-display-the-second-largest-value  
category: "c#"  
tags: ["c#", ".net", "java"]  
reading_time: 2 minutes  

---

# Write a program that take N integer number as input and display the second largest value.

Write a [program](https://www.mindstick.com/blog/12337/scaling-up-your-mentorship-program) that take N [integer](https://answers.mindstick.com/qa/113667/write-code-for-roman-to-integer) number as [input](https://www.mindstick.com/forum/159209/how-can-i-read-convert-an-input-stream-into-a-string-in-java) and display the [second largest](https://www.mindstick.com/forum/161531/find-the-second-largest-number-in-a-list-in-python-with-explanation) [value](https://www.mindstick.com/articles/23219/an-optimized-description-adds-value-to-experience-and-in-turn-effectively-guest-posting-packages) but doesn't use the array.

## Replies

### Reply by Ravi Vishwakarma

First of all,

what is [second](https://answers.mindstick.com/qa/41761/how-did-the-second-industrial-revolution-influence-women-s-roles-in-society) largest value, like we have 5 number of a series 12,45,78,15,23. in this series 78 is the first largest value, 45 is the second largest value, and 23 is the third largest value so on.

## Program

```
#include <stdio.h>#include <limits.h>int main(){    int N = 0, fMax, ScMax, num;    fMax = ScMax = INT_MIN;    printf('Enter the value: ');    scanf('%d',&N);    for(int i = 1; i<=N; i++){        printf('Enter the %d value: ', i);        scanf('%d',&num);            // Condition for finding the second largest value                if(num>fMax)        {            ScMax = fMax;            fMax = num;        }        else if(num<fMax && num>ScMax)            ScMax = num;    }    printf('\nFirst largest value : %d\n',fMax);    printf('Second largest value : %d',ScMax);    return 0;}
```

**Output:**\

```
Enter the value: 5
Enter the 1 value: 45
Enter the 2 value: 28
Enter the 3 value: 96
Enter the 4 value: 0
Enter the 5 value: 12
First largest value : 96
Second largest value : 45
```


---

Original Source: https://www.mindstick.com/forum/156802/write-a-program-that-take-n-integer-number-as-input-and-display-the-second-largest-value

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
