top of page
Writer's pictureanitadevkar

Find Largest Element from an array

C program to find largest element from an array

#include <stdio.h>

int main()

{

int a[15],n,i,large;

printf("Enter how many elements do you want to store into an array");

scanf("%d",&n);

for(i=0;i<n;i++) //accepting array elements from user

{

printf("Enter %d value=",i+1);

scanf("%d",&a[i]);

}

printf("Entered Values are =");

for(i=0;i<n;i++) //Displaying array elements

{

printf("%d ",a[i]);

}

large=a[0]; //making first value as large

for(i=1;i<n;i++) //finding largest elements

{

if(large<a[i]) //comparing first value with other array element

{

large=a[i];

}

}

printf("\nLargest Elements from an array is = %d",large);

return 0;

}

Output: Testcase-1

Enter how many elements do you want to store into an array5

Enter 1 value=12

Enter 2 value=45

Enter 3 value=38

Enter 4 value=9

Enter 5 value=25

Entered Values are =12 45 38 9 25

Largest Elements from an array is = 45

3 views0 comments

Recent Posts

See All

C Program for pyramid of number

Program: #include <stdio.h> int main() { int i,j; for(i=5;i>0;i--) //for rows { for(j=1;j<=i;j++) //for columns j loop will iterate...

Program to print Triangle

Program: #include <stdio.h> int main() { int i,j; for(i=5;i>0;i--) //for rows { for(j=0;j<i;j++) //for columns j loop will iterate...

Comentarios


bottom of page