Write a program to enter data into one-dimensional array. Find out the maximum value and its location in the array and print the result on the screen.
So let’s Write Code:
Code:
Write a program to enter data into a one-dimensional array. Find out the maximum value and its location.
#include"iostream"
using namespace std;
main()
{
float arr[10], max;
int loc, i = 0;
while(i<=9)
{
cout<<"Value for element "<<i<<" ? ";
cin>>arr[i];
i++;
}
max = arr[0];
i = 1;
while(i<=9)
{
if(max<arr[i])
{
max = arr[i];
loc = i;
}
i++;
}
cout<<"\nMaximum value is :"<<max<<endl;
cout<<"Location of value in array :"<<loc+1;
}
Hope You will learn Something. Happy Coding.
Visit my YouTube Channel as Well๐ https://www.youtube.com/watch?v=JuIHQ9cLSEw&list=PLbIhkHxfUIItTdcyCb34uRIrPJbXBndIl&index=4
Click on the below Links for more Programming Exercises:
Conditional Structure Exercises: ๐https://myustaadg.com/category/programming-exercises/conditional-structures-exercises/
Array Exercises: ๐https://myustaadg.com/category/programming-exercises/arrays-exercises/