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[1]
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[1];
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[25], 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[0]; small = a[0]; 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

CreatedOct 11, 2014

UpdatedDec 25, 2014

Views22,940
You May Like
Write a C program to count the lines, words and characters in a given text.
Write a C program to find the roots of a quadratic equation
.
Write a C program to find the sum of individual digits of a positive integer.
Write a C program to generate all the prime numbers
between 1 and n, where n is a value supplied by the user.
Write a C program, which takes two integer operands and one operator from the user, performs the operation and then prints the result. (Consider the operators +,,*, /, % and use switch statement
)
Write C programs that use both recursive
and nonrecursive functions
 To find the
factorial
of a given integer.  To find the
GCD
(greatest common divisor) of two given integers.