Write a program to input elements in an array and sort array using pointers array in ascending or descending order using function pointers.

Sort an Array in Ascending or Descending order using Function Pointers

Write a program to input elements in an array and sort array using pointers array in ascending or descending order using function pointers.

Object: Write a C++ program to input elements in an array and sort array using pointers. How to sort an array in ascending or descending order using function pointers in C programming. Logic to sort an array using pointers in program.
Example
Input
Input array elements: 10 -1 0 4 2 100 15 20 24 -5
Output
Array in ascending order: -5, -1, 0, 2, 4, 10, 15, 20, 24, 100,
Array in descending order: 100, 24, 20, 15, 10, 4, 2, 0, -1, -5, C++ projects for beginners with source code

Code:

#include<iostream>
#include<conio.h>
using namespace std;
void main()
{
     int num[10],i,j,temp;
     cout<<“Enter Any Numbers:\n”;
     for(i=1;i<=10;i++)
     {
         cin>>num[i];
     }
     cout<<“Inpute Array is: “;
     for(i=1;i<=10;i++)
     {
         cout<<num[i]<<” “;
     }

     for(i=1;i<=10;i++)
     {
         for(j=1;j<=10-i;j++)
         {
             if(num[j]>num[j+1])
             {
                 temp=num[j];
                 num[j]=num[j+1];
                 num[j+1]=temp;
              }
         }
     }
     cout<<“\n\nArray in Ascending Order: “;
     for(j=1;j<=10;j++)
     {
         cout<<num[j]<<” “;
     }
     cout<<“\n\nArray in Descending Order: “;
     for(j=10;j>=1;j–)
     {
         cout<<num[j]<<” “;
     }
     _getch();
}

Output:

Write a program to input elements in an array and sort array using pointers array in ascending or descending order using function pointers.

M.A Siddiqui

Hi, I am M.A Siddiqui. I'm a Computer Science Student, In this website, I'm teaching you Multiple languages and provides Projects and other Subjects Notes.

You may also like...

1 Response

  1. June 14, 2020

    […] Write a program to input elements in an array and sort array using pointers array in ascending or de… […]

Leave a Reply

Your email address will not be published. Required fields are marked *