Skip to content

MyUstaadG

Learn to Serve

  • Computer Science
    • Software
    • Computer Tips
    • Coding
      • Conditional Structures Exercises
      • Loops Exercises
      • Arrays Exercises
      • Python Exercises
    • Microsoft Office
      • MS Excel
      • MS Word
  • Videos
    • Funny Videos
    • Health and Fitness Videos
    • PUBG Videos
    • Technology Videos
  • News
  • Funny
  • Memes
  • Playwright Tutorials
  • Tutorials
  • Toggle search form

Write a program that inputs values in an array and finds out the largest value from the array using a function.

Posted on October 15, 2021 By myustaadg.com
Spread the love

Write a program that inputs values in an array and finds out the largest value from the array using a function.

So let’s Write Code:

Introduction to C++ Programming | Download and Install Dev C++ Compiler

Let’s build logic First:

Algorithm for code:

  • Step 1: Start
  • Step 2: Declare an array and variables i, max.
  • Step 3: Initialize i = 0;
  • Step 4: Take inputs from user.
  • Step 5: Traverse and Compare every element with current max element.
  • Step 6: Print result.
  • Step 7: Program end.

Code:

Write a program that inputs values in an array and finds out the largest value from the array using a function.

#include<iostream>
using namespace std;
main()
{
long arr[5], i;
long largest(long []), max;
i = 0;
while(i<=4)
{
cout<<"Enter value in element "<<i+1<<" of array ? ";
cin>>arr[i];
i++;
}
max = largest(arr);
cout<<"Largest value entered in the array : "<<max;
}
// definition of largest() function
long largest(long x[])
{
int mx = x[0];
for(int i = 1; i<=4; i++)
if (mx < x[i])
mx = x[i];
return mx;
}

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/

Arrays Exercises, Programming Exercises Tags:algorithm exercises, algorithm to find largest number in an array, algorithm to find max number in an array, algorithm to find maximum number in an array, Array Exercises, Array exercises in C++, array in Object oriented programming, array in OOP, Arrays in C++, C++ program t find largest element of an array, c++ program to find largest element in an array, c++ program to find maximum element fromarray, c++ program to find maximum element in array, C++ program to find the largest element in an array', c++ program to find the largest number in an array, finding the largest element in an array, how to find largest element in an array, how to find maximum values in array, how to find maximum values in array using function, how to find the largest number in an array in c++, loop exercises, program to find largest element in array, program to find largest element of array using function, write a program in c++ to get the largest element of an array using the function, Write a program that inputs values in an array and finds out the largest value from the array using a function.

Post navigation

Previous Post: Write a program that inputs ten values into an array. It finds out the average value of the array
Next Post: Write a program that inputs marks of N students and finds out the grade of each student.

More Related Articles

Write a program that assigns values to the individual elements of an array and displays the values of the array. Arrays Exercises
Write a program that inputs real values into float type array. It reads the value of each element of float type array and assigns to int type array. Arrays Exercises
Write a program that gets 5 integer values into an array and then displays the values of the elements of the array in reverse order. Arrays Exercises
Develop a program that inputs ‘n’ values in a list and prints the product of the value and the position at which it resides in the list. Arrays Exercises
Write a program that initializes values in two tables A and B. It adds tables A and B and stores result into table C. It also displays the values of three tables in tabular form on the screen. Arrays Exercises
Write a program that inputs fifteen integer values in an array. It finds out all the prime numbers. Arrays Exercises

Copyright © 2022 MyUstaadG.

Powered by PressBook Blog WordPress theme