第一题
#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++)
scanf("%d", &a[i]);
selection_sort(n, a);
printf("In sorted order: ");
for (int i = 0; i < n; i++)
printf("%d ", a[i]);
system("pause");
return 0;
}
第二题
#include <stdio.h>
#include<string>
float js(float income)
{
float out;
if (income < 750)
out = 750 * 0.01;
else if (income < 2250)
out = (income - 750)*0.02 + 7.50;
else if (income < 3750)
out = (income - 2250)*0.03 + 37.50;
else if (income < 5250)
out = (income - 3750)*0.04 + 52.50;
else if (income < 7000)
out = (income - 7000)*0.05 + 142.50;
else
out = (income - 750)*0.06 + 230.0;
return out;
}
int main(void)
{
float income;
printf("Enter your income:");
scanf_s("%f", &inc