- 6

Highlight the errors and rewrite the whole code with output

#include <iostream> int main(){ //declare and define an array int arr[]={10, 1, 20, 2, 30}; //size of the array //total size/size of an element int size = sizeof(arr)/sizeof(int); //calling sort() to sort array elements sort(arr, arr+5, greater<>()); //printing sorted elements cout<<"Sorted elements are: "; for(int i=0; i<size; i--) cout<<arr[i]<<" "; getche():

12th Jan 2018, 1:57 AM
Alishbah Athar
Alishbah Athar - avatar
3 Respostas
+ 6
Sololearn is for learning and not for solving someone's homework, but i can give you some hint to solve the above question. 1. If your code is not written in C++ 11 or newer standard version of c++ , so you should use .h after each header file. If it is then use using namespace std; 2. semicolon (;) is used in the end of each statement to terminate it. 3. sort(arr,arr+size,greater<>()) is used to sort array in descending order. 4. carefully see that you've used increment or decrement operator in loop statement to get corect output.
12th Jan 2018, 3:14 AM
Lakshay
Lakshay - avatar
0
#include <iostream> int main(){ //declare and define an array int arr[]={10, 1, 20, 2, 30}; //size of the array //total size/size of an element int size = sizeof(arr)/sizeof(int); //calling sort() to sort array elements sort(arr, arr+5, greater<>()); //printing sorted elements cout<<"Sorted elements are: "; for(int i=0; i<size; i--) cout<<arr[i]<<" "; getche(): Your welcome
15th Jan 2018, 12:20 AM
Someone Else
Someone Else - avatar