Please help me Solve the question on the c program and I ho
Solution
what i have tried doing is sending the int pointer from the main function to the input function and taken the size there and tried allocating memory in the input function
#include<iostream>
int input(int array[])
{
using namespace std;
cout<<\"Enter size: \";
int n;
cin>>n;
cout<<\"Enter \"<<n<<\" values: \";
array=(int *)malloc(n*sizeof(int));
for(int i=0;i<n;i++)
cin>>array[i];
return n;
}
void print(int n,int array[])
{
using namespace std;
for(int i=0;i<n;i++)
cout<<\" \"<<array[i];
}
void Bubble(int n,int array[])
{
for(int i=0;i<n-1;i++)
{
for(int j=i+1;j<n-i-1;j++)
{
if (array[j] > array[j+1])
{
int t=array[j];
array[j]=array[j+1];
array[j+1]=t;
}
}
}
}
int main()
{
using namespace std;
int *array;
int n=input(array);
cout<<\"Before sorting: \";
print(n,array);
Bubble(n,array);
cout<<\"After sorting: \"
print(n,array);
return 0;
}

