C program to find big element & it's position using array
Problem Description
This program takes the 3 numbers and finds the biggest among all and show it's position.
Problem Solution
1. Take the size of array.
2. take the element.
3. initialize arr[0] into big like big=arr[0].
4. for loop check the element with big in IF block .
5. print the big number and it's position.
2. take the element.
3. initialize arr[0] into big like big=arr[0].
4. for loop check the element with big in IF block .
5. print the big number and it's position.
Program codes:-
here the program of finding biggest of three number run this in your Linux, DEV C++,turbo c++ main()
{
int n,i,pos,big,arr[20];
printf("\n enter the size of array:");
scanf("%d",&n);
printf("\n enter the element of array:");
for(i=0;i<n;i++)
{
printf("\n arr[%d]=",i);
scanf("%d",&arr[i]);
}
big=arr[0];
for(i=0;i<n;i++)
{
if(arr[i]>big)
{
big=arr[i];
pos=i;
}
}
printf("\n big number is :%d",big);
printf("\n big number's position:%d",pos);
}
Program explanation:-
1. for example we take size of array is 5.
2. enter the elements by for loop .
3. for example arr[0]=2, arr[1]=5,arr[2]=6, arr[3]=4,arr[4]=7.
4. initialize big into arr[0] like big=arr[0].
5. then it checks element in if blocks in second for loop.
6. if it greater than big then big=arr[i] and pos=i.
Output of this program:-
Comments
Post a Comment
please subscribe my blog and let me suggest how I improve this site