C Program to Find Largest and Smallest Number in an Array

C Program to Find Largest and Smallest Number in an Array

C program to find largest and smallest number in an array; Through this tutorial, we will learn how to find largest and smallest number from an array using standard method and function in c programs.

Programs to Find Largest and Smallest Number in an Array

Use the following programs to find largest and smallest number from an array using standard method and function in c:

  • C Program to Find Largest Number in an Array using Standard Method
  • C Program to Find Largest Number in an Array using Function

C Program to Find Largest and Smallest Number in an Array using Standard Method

#include <stdio.h>
 
int main()
{
    int a[1000],i,n,min,max;
   
    printf("Enter size of the array : ");
    scanf("%d",&n);
 
    printf("Enter elements in array : ");
    for(i=0; i<n; i++)
    {
        scanf("%d",&a[i]);
    }
 
    min=max=a[0];
    for(i=1; i<n; i++)
    {
         if(min>a[i])
		  min=a[i];   
		   if(max<a[i])
		    max=a[i];       
    }
     printf("minimum of array is : %d",min);
          printf("\nmaximum of array is : %d",max);
 
 
    return 0;
}

The output of the above c program; as follows:

Enter size of the array : 5
Enter elements in array : 1 2 3 5 4
minimum of array is : 1
maximum of array is : 5

C Program to Find Largest and Smallest Number in an Array using Function

#include <stdio.h>
 
 int sumofarray(int a[],int n)
 {
 	int min,max,i;
 	min=max=a[0];
    for(i=1; i<n; i++)
    {
         if(min>a[i])
		  min=a[i];   
		   if(max<a[i])
		    max=a[i];       
    }
    
    printf("minimum of array is : %d",min);
    printf("\nmaximum of array is : %d",max);
 }
int main()
{
    int a[1000],i,n,sum;
   
    printf("Enter size of the array : ");
    scanf("%d", &n);
 
    printf("Enter elements in array : ");
    for(i=0; i<n; i++)
    {
        scanf("%d",&a[i]);
    }
    sumofarray(a,n);
 
 
    
}

The output of the above c program; as follows:

Enter size of the array : 5
Enter elements in array : 8 9 10 2 5
minimum of array is : 2
maximum of array is : 10

Recommended C Programs

AuthorAdmin

Greetings, I'm Devendra Dode, a full-stack developer, entrepreneur, and the proud owner of Tutsmake.com. My passion lies in crafting informative tutorials and offering valuable tips to assist fellow developers on their coding journey. Within my content, I cover a spectrum of technologies, including PHP, Python, JavaScript, jQuery, Laravel, Livewire, CodeIgniter, Node.js, Express.js, Vue.js, Angular.js, React.js, MySQL, MongoDB, REST APIs, Windows, XAMPP, Linux, Ubuntu, Amazon AWS, Composer, SEO, WordPress, SSL, and Bootstrap. Whether you're starting out or looking for advanced examples, I provide step-by-step guides and practical demonstrations to make your learning experience seamless. Let's explore the diverse realms of coding together.

Leave a Reply

Your email address will not be published. Required fields are marked *