Search This Blog
Welcome to 1printf(), your ultimate destination for C, C++, Linux, Data Structures, and Microcontroller programming! ๐ ๐นLearn advanced coding techniques in C& C++ ๐นMaster Linux internals & shell scripting ๐นDeep dive into Data Structures & Algorithms ๐นExplore Embedded Systems & Microcontrollers (8051,UART, RTOS) ๐นGet hands-on coding tutorials, project ideas,and interview preparation tips Whether you're a beginner or an experienced programmer, this channel will help you
Featured
- Get link
- X
- Other Apps
C program to find the largest element in an array using simple iteration
๐ Find Largest Element in an Array (C Program)
#include<stdio.h>
int main( )
{
int num,a[100];
printf("Enter the size of the array:\n");
scanf("%d",&num);
if(num<=0)
{
printf("Invalid array size");
return 1;
}
printf("Enter %d elements into the array:\n", num);
for(int i=0;i<num;i++)
{
scanf("%d",&a[i]);
}
int max=a[0];
for(int i=0;i<num;i++)
{
if(a[i]>max)
{
max=a[i];
}
}
printf("The largest element in array is %d\n",max);
}
๐ Explanation:
๐น The program first reads the size and elements of the array.
๐น It initializes `max` with the first element.
๐น Then it iterates through all elements and updates `max` whenever a larger value is found.
๐น Finally, it prints the largest element.
๐งช Sample Output:
Enter the size of the array:
5
Enter 5 elements into the array:
10 45 23 89 34
The largest element in array is 89
๐ท️ Keywords:
C program largest element, find max in array, array maximum value, beginner array program, C logic for max element
Popular Posts
C++ Program for Hybrid Inheritance (All Types Together)
- Get link
- X
- Other Apps
C++ Program for Function Overloading Example
- Get link
- X
- Other Apps
Comments
Post a Comment