Advertisement

C语言程序设计现代方法(第2版)第九章习题

阅读量:

第一题

复制代码
    #include <stdio.h>
    #include<string>
    
    void selection_sort(int n, int a[]) 
    {
    
    	int i, j, max = a[0];
    
    	for (i = 0; i < n; i++) 
    	{
    		if (max <= a[i]) 
    		{
    			max = a[i];
    			j = i;
    		}
    	}
    	a[j] = a[n - 1];
    	a[n - 1] = max;
    	n--;
    	if (n == 0) 
    		return;
    	else
    		selection_sort(n, a);
    }
    int main(void)
    {
    	int n;
    	printf("How many numbers do you want to resevse? ");
    	scanf("%d", &n);
    	int a[99];
    	printf("Enter the number you want: ");
    	for (int i = 0; i < n; i++)

全部评论 (0)

还没有任何评论哟~