#include<stdio.h>
int main(){
int n;//输入一个数,表示有几个数进行比较//
scanf("%d",&n);
if(n==1){
printf("0\n0"); //直接输出//
}else if(n>=2){
double a[n]; //建立一个浮点数的数组,for语句读取数的多少,存入a数组。//
int i;
for(i=0;i<n;i++){
scanf("%lf",&a[i]);
}
double max=a[0];
double min=a[0];
for(i=0;i<n;i++){
if(a[i]>max){ //如果a[i]>a[0]时,最大的数为a[i],以下同理。//
max=a[i];
}
if(a[i]<min){
min=a[i];
}
}
printf("%g\n%g",min,max); //输出最小与最大的数//
}else{
printf(" ");
}
return 0;
}
#include<stdio.h>
int main() {
int k, x, N,i;
scanf("%d", &N);
int a[100];//有序数组
for ( i = 0; i < N; i++) {
scanf("%d", &a[i]);
}
int temp, j;
for ( i = 1; i < N; i++)
{
j = i - 1;
temp = a[i];
while (a[j] > temp&&j >= 0)
{
a[j + 1] = a[j];
j--;
}
a[++j] = temp;
}
for ( i = 0; i < N; i++)
{
printf("%d", a[i]);
if(i<N-1)
printf(" ");
}
printf("\n");
return 0;
}#include<stdio.h>
int main() {
int k, x, N,i;
scanf("%d", &N);
int a[100];//有序数组
for ( i = 0; i < N; i++) {
scanf("%d", &a[i]);
}
int temp, j;
for ( i = 1; i < N; i++)
{
j = i - 1;
temp = a[i];
while (a[j] > temp&&j >= 0)
{
a[j + 1] = a[j];
j--;
}
a[++j] = temp;
}
for ( i = 0; i < N; i++)
{
printf("%d", a[i]);
if(i<N-1)
printf(" ");
}
printf("\n");
return 0;
}
数组的排序与查找正在学。
#include<stdio.h>
int main() {
int k, x, N,i;
scanf("%d", &N);
int a[100];//有序数组
for ( i = 0; i < N; i++) {
scanf("%d", &a[i]);
}
int temp, j;
for ( i = 1; i < N; i++)
{
j = i - 1;
temp = a[i];
while (a[j] > temp&&j >= 0)
{
a[j + 1] = a[j];
j--;
}
a[++j] = temp;
}
for ( i = 0; i < N; i++)
{
printf("%d", a[i]);
if(i<N-1)
printf(" ");
}
printf("\n");
return 0;
}