C Program to find Largest Element of an Array using Loops
dev-suman-ch.blogspot.com
- Write a C Program to find Largest Element of an Array using Loops.
Explanation
Array is a data structure consisting of a collection of homogenous data type or element (values or variables), each identified by at least one array index or key. An array is stored in such a manner that the position of each element can be found out from its index tuple by using a mathematical formula. The simplest data structure is a linear array, also known as one-dimensional array.
Arrays are among the most important data structures and are used in almost every program. They can be also used to implement many other data structures, such as linked-lists and stacks. The most important fact is that arrays are linear datatypes in which data is stored in sequence. In many internal and external storage devices, the memory is a one-dimensional array of words, whose indices are their addresses. We can access the elements if we know their indexes directly so, we can say that random access is possible in array.
Program
#include <stdio.h>
int main () {
int n,i,large;
printf("Enter The Array Range:\n");
scanf("%d", &n);
int array[n];
for (i = 0; i < n; i++) {
printf("Enter Number %d: ", i + 1);
scanf("%d", &array[i]);
}
large = array[0];
for (i=0; i < n; i++) {
if (large < array[i])
large = array[i];
}
printf("Largest Number is: %d", large);
return 0;
}
Output: Enter The Array Range: 5 Enter Number 1: 99 Enter Number 2: 55 Enter Number 3: 87 Enter Number 4: 22 Enter Number 5: 44 Largest Number is:99
Algorithm
Step 1: Start
Step 2: Declare n,i,large
Step 3: read n from user and declare Array[n]
Step 4: using loop for read elements
Step 5: assign large = array[0]
Step 6: Repeat Until i<=n-1
6.1: if(Array[i]>large), set large=Array[i]
6.2: increment i=i+1
Step 7: Print "The largest Number is:" large
Step 8: Stop
FlowChart
pic
Genrerating Link.... 15 seconds.
Your Link is Ready.