# Write a C program to find the largest integer in a list of integers.

#### Algorithm:

```Step 1: Start
Step 2: Read n and a[i] as integers
Step 3: Declare maxpos as 1
Step 4: Assign max ← A
Step 5: for i: 1 to n increment i by 1
begin
if(max < A[i])
begin
max ← A[i];
maxpos ← i;
end
end
Step 6: Assign min← A;
Declare minpos as 1;
Step 7: for i: 1 to n increment i by 1
begin
if(min>A[i])
begin
min ← A[i];
minpos ← i;
end
end
Step 4: Print max, min
Step 5: Stop```

#### Program:

```#include <stdio.h>
#include <conio.h>
void main()
{
int a, i, large, small, n;
clrscr();
printf("Enter the size of array(max 25)\n");
scanf("%d", &n);
printf("Enter any %d integer array elements\n",n);
for(i = 0; i < n; i++)
{
scanf("%d", &a[i]);
}
large = a;
small = a;
for(i = 1; i < n ; i++)
{
if(a[i] > large)
{
large = a[i];
}
if(a[i] < small)
{
small = a[i];
}
}
printf("The largest element from the given array is %d \nThe smallest element  from the given array is %d", large, small);
getch();
}```

#### Input & Output:

```Enter the size of array(max 25)
5
Enter any 5 integers array elements
10 2 3 1 5
The largest element from the given array is 10
The smallest element from the given array is 1```
• Created
Oct 11, 2014
• Updated
Dec 25, 2014
• Views
23,279
You May Like