- 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():
2 ответов
+ 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.
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