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