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 sorts one-dimensional array of 5 elements in ascending order using insertion sort method.

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

Write a program that sorts one-dimensional array of 5 elements in ascending order using insertion sort method.

So let’s Write Code:

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

Code:

Write a program that sorts a one-dimensional array of 5 elements in ascending order using the insertion sort method.

#include"iostream" 
using namespace std;
void main(void)
{
int abc[4], val, u, i;
cout<<"Enter 5 values "<<endl;
for(i = 0; i<=4; i++)
cin>>abc[i];
for(u = 0; u<=4; u++)
{
val = abc[u];
for(i = u; i >=0 && val<abc[i-1]; i--)
abc[i] = abc[i-1];
abc[i] = val;
}
cout<<"Sorted array "<<endl;
for(i = 0; i<=4; i++)
cout<<abc[i]<<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 declaration in c++, Array Exercises, Array exercises in C++, array in Object oriented programming, array in OOP, Arrays, arrays arrays in c++, arrays codes, Arrays exercises, Arrays in C++, Arrays in C++ Programming with examples, Arrays in Programming, Arrays with example, C++ Arrays, c++ arrays declaration and initialization, C++ Arrays with examples, Creating and Using Arrays, Data Structure and Algorithms Insertion Sort, How can I sort arrays and data in C++, how do you initialize an array in c++, how to display elements of arrays, Insertion Sort, Insertion sort (article) | Algorithms, Insertion Sort (With Code), insertion sort array sort in ascending odrer Code Example, insertion sort examples, Insertion Sort in C C++, Simple arrays code, sort a one-dimensional array of 5 elements in ascending order using the insertion sort method., Two Dimensional Arrays in C++ with Examples, Write a program that sorts one-dimensional array of 5 elements in ascending order using insertion sort method.

Post navigation

Previous Post: Write a program in C++ that inputs data into an array. It inputs a value from the user and searches this value in the array using sequential search.
Next Post: Write a program that inputs data into a string and searches the โ€˜vowelโ€™ characters from the string and displays on the screen.

More Related Articles

Write a program to input an array of 10 elements from the user and count the number of odd numbers and display it. Arrays Exercises
Write a program that deletes a value from a specified location of one-dimensional array of N elements. Arrays Exercises
Write a Program that Inputs Values into an Array and Displays the Values of the Array Arrays Exercises
Introduction to C++ Programming | Download and Install Dev C++ Compiler Programming 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 inputs values in an array and finds out the largest value from the array using a function. Arrays Exercises

Copyright © 2022 MyUstaadG.

Powered by PressBook Blog WordPress theme