Write a program to get an integer from the user (to enter the number of students) and store it in the num variable. Then, allocate the memory dynamically for the float array using new operator. Next enter data(student register number) into the array using pointer notation. Arrange register number from lower to highest. After this you no longer need the array, so deallocate the array memory using the delete operator.
#include <algorithm>
#include <iostream>
int main()
{
int num;
std::cout << "Enter the size of the array:" << std::endl;
std::cin >> num;
float* array = new float[num];
for (int i = 0; i < num; i++)
{
std::cout << "Enter registration number "<<i+1<< "of the student:" << std::endl;
std::cin >> array[i];
}
std::sort (array, array + num);
delete array;
array = nullptr;
return 0;
}
Comments
Leave a comment