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 into an array and finds the smallest and largest value from it.

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

Write a program that inputs different values into an array and finds out the smallest value and largest value from it.

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 smallest, largest and i.
  • Step 3: Take inputs from user.
  • Step 4: Set Smallest and largest equal to arr[0].
  • Step 5: Set condition and compare array values one by one.
  • Step 6: Print values.
  • Step 7: End Program

Code:

Write a program that inputs different values into an array and finds out the smallest value and largest value from it.

#include<iostream>
using namespace std;
main()
{
int ar[10], smallest, largest, i;
for(i=0; i<=9; i++)
{
cout<<"Enter value in element "<<i<<" ? ";
cin>>ar[i];
}
smallest = largest = ar[0];
for(i=1; i<=9; i++)
{
if(smallest > ar[i])
smallest = ar[i];
if(largest < ar[i])
largest = ar[i];
}
cout<<"Largest value in array is : "<<largest<<endl;
cout<<"Smallest value in array is : "<<smallest<<endl;
}

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:Array Exercises, Array exercises in C++, array in Object oriented programming, array in OOP, Arrays in C++, C ++ program to find maximum and minimum element in array, c program to find smallest and largest element in an array, C++ Program To Find Maximum & Minimum Element In Array, c++ program to find smallest and largest element in an array, C++ Program to Find the Largest and Smallest Elements in an array, Find smallest and largest element in an array, How do you find the largest and smallest value in an array in c++?, How do you find the maximum and minimum value of an array?, How do you find the smallest element in an array?, How do you find the smallest number in an array in C++?, How to find the largest and smallest number in an array in c++, Program to find largest element in an array, Program to find Maximum and minimum number in C++, program to find smallest and largest element in an array, Write a program that inputs different values into an array, Write a program that inputs different values into an array and finds out the largest value from it., Write a program that inputs different values into an array and finds out the smallest value, Write a program that inputs different values into an array and finds out the smallest value and largest value from it.

Post navigation

Previous Post: Write a program to input an array of 10 elements from the user and count the number of odd numbers and display it.
Next Post: Write a program that inputs data into a table and displays it on the screen in tabular form.

More Related Articles

Write a program that asks the user their age and monthly income and shows on the screen whether the user has to pay taxes or not | Python Programming Programming Exercises
Write a program that inputs data into a string and searches the โ€˜vowelโ€™ characters from the string and displays on the screen. Arrays Exercises
Write a program that initializes roll numbers and marks of different subjects in a two-dimensional array. Arrays Exercises
Write a program that asks the user their annual income and shows on the screen the tax rate that corresponds to them | Python Programming Programming Exercises
Write a program that inserts a new value at a specified location into one-dimensional array of N elements. Arrays Exercises
Write a program that assigns values to the individual elements of an array and displays the values of the array. Arrays Exercises

Copyright © 2022 MyUstaadG.

Powered by PressBook Blog WordPress theme