关于C++的题目,求详细解答,谢谢!!

来源:百度知道 编辑:UC知道 时间:2024/09/24 10:10:58
Writing a function to sort an integer array from lowest to highest by applying either selection sort or bubble sort. The main function and sort function prototype is already given to you. To write the function below the main function.

void SortIntegerArray(int a [], int n);
#include <stdio.h>
#define N 10
main()
{
int i,array[N];
printf(“Input the number to be sorted:”);
for(i=0;i<N;i++)
scanf(“%d”,&array[i]);

SortIntegerArray(array,N);

for(i=0;i<N;i++)
printf(“%d”,array[i]);
}

void SortIntegerArray(int a[], int n){
int i,j,temp;n--;
for(i=0;i<n;i++)
for(j=0;j<n-i;j++)
if(a[j]>a[j+1]){temp=a[j];a[j]=a[j+1];a[j+1]=temp;}
};
#include <stdio.h>
#define N 10
void main()
{
int i,array[N];
printf(\"Input the number to be sorted:\");
for(i=0;i<N;i++)
scanf(\"%d\",&array[i]);

SortIntegerArray(array,N);

for(i=0;i<N;i++)
printf(\"%d \",array[i]);