Find elements

C program to find largest elements of an Array

C program to find largest elements in an Array

In this tutorial, we will discuss the concept of C program to find the largest elements in an Array

In this topic, we will discuss how to find Biggest number in an Array in C language

This program gets “n” number of elements and Enter the elements of the array as input from the user. then, this program finds and displays the largest elements from the array using for loops.

This is a C program to find the largest number in an array

In this programs, we can see step by step procedure for completion of the program.

  • Declare an array of fixed capacity
  • Essential variable declaration
  • Taking the size of the array as input from the user
  • Taking the elements of the array as input from the user
  • loop for find the smallest and largest value
  • Display result on the screen

Program 1

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int arr[30];//array declaration
    int length,i, max; //essential variable declaration
    printf("Enter the length of the array: ");
    scanf("%d", &length);//get input from user for length
    for(i=0; i<length; i++){//iterates the loop for take input
    printf("Enter element %d: ",i+1);//enter elements for array
    scanf("%d", &arr[i]);//store the elements in array
    }
    max=arr[0];//assume first element as smallest value

    for(i=0; i<length; i++){//iterates the loop for find maximum
    if(max<arr[i]){
        max=arr[i];//assign the maximum value to max
    }
    }
    printf("\nlargest elements is: %d",max);
getch();//display the elements on the screen
    return 0;
}

When the above code is compiled and executed, it produces the following results

Enter the length of array: 5 
Enter element 1: 45 
Enter element 2: 87 
Enter element 3: 98 
Enter element 4: 56 
Enter element 5: 78 

largest elements is 98

 

Suggested for you

Operator in C language

For loop in C language

If statements in C language

Data type in C language

Single dimension array in C language

Java program to find largest and smallest number in an array
C program to find smallest and largest number in an array
Karmehavannan

I am Mr S.Karmehavannan. Founder and CEO of this website. This website specially designed for the programming learners and very especially programming beginners, this website will gradually lead the learners to develop their programming skill.

Recent Posts

PHP Star Triangle pattern program

PHP Star Triangle pattern program In this tutorial, we will discuss about PHP Star Triangle…

2 months ago

PHP Full Pyramid pattern program

PHP Full Pyramid pattern program In this tutorial, we will discuss about PHP Full Pyramid…

2 months ago

5 methods to add two numbers in Java

5 methods to add two numbers in Java In this tutorial, we will discuss the…

2 months ago

Python Full Pyramid star pattern program

Python full Pyramid star pattern program In this tutorial, we will discuss  the concept of…

5 months ago

Write a function or method to convert C into F -Entered by user

Write a function or method to convert C into F -Entered by the user In…

10 months ago

How to write a function or method to convert Celsius into Fahrenheit

How to write a function or method to convert Celsius into Fahrenheit In this tutorial,…

10 months ago