Can anyone help me with this code.It is showing fatal error | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Can anyone help me with this code.It is showing fatal error

# include<iostream.h> # include<conio.h> void read(int[],int&); void display(int[],int); void swap(int &,int &); void sort(int[],int &n); int main() { int n,arr[100]; clrscr(); read(arr,n); display(arr,n); sort(arr,n); display(arr,n); getch(); return 0; } void read(int a[],int &n) { cout<<"enter number of elements in array:"; cin>>n; cout<<"enter data:"<<endl; for(int i=0;i<n;i++) cin>>a[i]; } void display(int a[],int n) { cout<<endl<<"array is......"<<endl; for(int i=0;i<n;i++) cout<<a[i]<<"\t"; cout<<endl<<"......."; } void swap(int &i,int &j) { int temp; temp=i; i=j; j=temp; } void sort(int a[],int &n) { for(int i=0;i<n-1;i++) { for(int j=0;j<(n-i-1);j++) { if(a[j]<a[j+1]) swap(a[j],a[j+1]); } } }

25th May 2021, 9:17 AM
SUMIT SANTOSH SAHU
SUMIT SANTOSH SAHU - avatar
3 Answers
0
Hey SUMIT SANTOSH SAHU ! I'm not very good in C++, but I think it would be helpful to anyone who wants to attempt your question if you tell them what you are trying to do?!
25th May 2021, 9:54 AM
Vachila64☕
Vachila64☕ - avatar
0
Write a program in C++ to sort the numbers in an array using separate functions for read, display, sort and swap.
25th May 2021, 10:04 AM
SUMIT SANTOSH SAHU
SUMIT SANTOSH SAHU - avatar
0
Have you copied the code from somewhere? Because I doubt you wrote all that code without realising there were so many errors in your code. Also, from the next time, please save your code in the code playground and link the code here. It makes it easier to reference line numbers and compiler errors. Anyways, the first error in your code is that there is no header file <iostream.h>. It is simply <iostream>. Then, you are including the <conio.h> header. That header is obsolete and not supplied with mordern compilers. You don't need it too, so just remove these 3 lines `#include <conio.h>` `clrscr();` `getch();` The last error is that you are using objects/functions of the std namespace (like cout, cin, end) without the 'std::' prefix. Either prefix them with 'std::' or use the namespace std globally by doing `using namespace std;` Your code will work if you fix these errors. Also, your program currently sorts the array in descending order. I hope that's how you want to sort.
25th May 2021, 11:17 AM
XXX
XXX - avatar