Instruction: Explain the function of the program line by line thoroughly. Program: #include using namespace std; void sort(int a[], int num){     for(int i =0; i < num; i++){         for(int j = i+1; j < num; j++){             if(a[j] < a[i])

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter15: Recursion
Section: Chapter Questions
Problem 6PE
icon
Related questions
Question
100%

Instruction: Explain the function of the program line by line thoroughly.

Program:

#include <iostream>
using namespace std;

void sort(int a[], int num){
    for(int i =0; i < num; i++){
        for(int j = i+1; j < num; j++){
            if(a[j] < a[i])
                a[i] = a[i] + a[j] -(a[j] = a[i]);
        }
    }
}

int main()
{
    int n;
    cout<<"Enter number of integers: ";
    cin >> n;
    
    int *a = new int[n];            // Dynamic memory allocation using new.
    int val;
    for(int i =0; i < n; i++){
        cout << " Enter integer No. "<< i+1 << ": ";
        cin >> val;
        a[i] = val;
    }
    sort(a,n);
    cout << "\nSorted Integers: ";
    for(int i =0; i < n; i++)   cout << a[i] << " ";
    
    return 0;
}

Expert Solution
steps

Step by step

Solved in 3 steps

Blurred answer
Knowledge Booster
Fundamentals of Multithreaded Algorithms
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT