How to Find Largest Number in Array in C
Here you will learn and get the example code to find largest number in array in c programming. We will be using integer array here. Follow the following steps to complete the program:-
Step 1 declare int array[5] and temp=0;
Step 2 Input 5 numbers in array list.
Step 3 Start a loop from first element to the last element of array.
Step 4 In between of loop check if temp value is less than array[i] value, than assign array value to temp;
Step 5 Print the value of temp variable as largest number.
Program to Find Largest Number in Array in C
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | #include<stdio.h> int main() { int ar[10], i, temp=0; clrscr(); printf("\nEnter 5 Numbers to find Largest number : "); for(i=0;i<5;i++) { scanf("%d", &ar[i]); } for(i=0;i<5;) { if(temp<ar[i]) temp=ar[i]; else i++; } printf("\nValue of Largest Element is %d", temp); getch(); } |
Output
Enter 5 Numbers to find Largest number : 3 4 5 2 1
Value of Largest Element is 5
Check out our other C programming Examples
Your website is very helpful for my BCA course. Thanks for providing such good programs.
Anil