Finding largest number and display their position
In this example, we will understand to find a largest number in an array and display their position and know how to write, compile and debug it in C language and also learn how to implement it in c.
In order to do this you will need
- Basic knowledge of c programming language.
- As well as know how to operate codeblocks.
An array is a fixed-size sequential collection of elements of same data types that share a common name.It is simply a group of data types. An array is a derived data type.An array is used to represent a list of numbers or a list of names.
So let's begin with our program
1.Open a codeblocks software.
2.Open new empty file.
3.Copy and paste the code from below.
Input code-
//Write a program for finding largest number in an array and display their position.
#include<stdio.h>
int main()
{
int n[5],i,loc,max;
printf("Enter any 5 numbers:\n");
for(i=0;i<=4;i++)
{
scanf("%d",&n[i]);
}
max=n[0];
for(i=0;i<=4;i++)
{
if(n[i]>max)
{
max=n[i];
loc=i+1;
}
}
printf("largest number is %d and is present at location %d",max,loc);
return 0;
}
Now simply build the code. Look for any error. Now run the code.
For output enter any five number you want and press enter key.
Click the following button to download a program for finding largest number in an array and display their position
Thats it.Thank you for scrolling.
Tags:
Array