C program to Find First Largest Element and Second Largest Element in an Array.

Interview Programming

First Largest Element and Second Largest Element in an Array.

Procedure:

#include <stdio.h>
int main()
{
    int arra[500], number, i;
    int FirstMax, SecondMax;

    printf("Enter Number of Elements in array\n");
    scanf("%d", &number);

    printf("Enter %d numbers \n", number);
    for(i = 0; i < number; i++){
        scanf("%d", &arra[i]);
    }

    FirstMax = SecondMax = -1;

    for(i = 0; i < number; i++){
        if(arra[i] > FirstMax){
            SecondMax = FirstMax;
            FirstMax = arra[i];
        }
        else if (arra[i] > SecondMax && arra[i] < FirstMax){
            SecondMax = arra[i];
        }
    }

    printf("First Largest Element : %d \nSecond Largest  Element: %d", FirstMax, SecondMax);
    return 0;
}

Output:

0 Comments

You may find interest following article

Complete Guide: Create Laravel Project in Docker Without Local Dependencies

Create Laravel Project Through Docker — No Need to Install PHP, MySQL, or Apache on Your Local Machine In this tutorial, I’ll show you how to create and run a full Laravel project using Docker containers. That means you won’t have to install PHP, MySQL, or Apache locally on your computer. By the end of this guide, you’ll have a fully functional Laravel development...