chore(C): add largestElement in array (#705)

pull/708/head
ANUJ BISHT 2022-02-23 18:43:42 +05:30 committed by GitHub
parent 7b07f177b9
commit e1f258ce04
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 63 additions and 0 deletions

View File

@ -6,6 +6,7 @@
- [Unique Elements in an array](arrays/unique-elements-in-an-array.c) - [Unique Elements in an array](arrays/unique-elements-in-an-array.c)
- [Reverse an array](arrays/reverse-array.c) - [Reverse an array](arrays/reverse-array.c)
- [Maximum difference](arrays/maximum-difference.c) - [Maximum difference](arrays/maximum-difference.c)
- [Largest Element](arrays/largestElement.c)
## Bit Manipulation ## Bit Manipulation

View File

@ -0,0 +1,62 @@
/******************************************************************************
Program to compute the largest element in array
******************************************************************************/
#include<stdio.h>
#define maxSize 100
int main()
{
int array[maxSize], size;
int max;
// Scanning the size of the array
printf("Enter the size of the array: ");
scanf("%d",&size);
// Scanning the elements of array
printf("Enter the %d elements of the array: \n",size);
for(int i=0; i<size; i++)
{
printf("Element [%d]: ",i);
scanf("%d",&array[i]);
}
// Printing the array
printf("The input array: \n");
for(int i=0; i<size; i++)
{
printf("%d ", array[i]);
}
// Assigning the first element of the array to max variable
max = array[0];
// Checking for elements maximum than value of max variable
for(int i=1; i<size; i++)
{
if(array[i] > max)
{
max = array[i];
}
}
// Printing out the result
printf("\nThe largest element of the array: %d",max);
return 0;
}
/******************************************************************************
OUTPUT SAMPLE
Enter the size of the array: 5
Enter the 5 elements of the array:
Element [0]: 1
Element [1]: 2
Element [2]: 3
Element [3]: 4
Element [4]: 6
The input array:
1 2 3 4 6
The largest element of the array: 6
******************************************************************************/