数组练习题10
Posted yuzhenghan
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了数组练习题10相关的知识,希望对你有一定的参考价值。
#include<stdio.h>
#include<stdlib.h>
int main(){
int a[5];
int i, j, t;
for (i = 0; i < 5; i++)
scanf("%d", &a[i]);
printf("
");
for (j = 0; j < 5 - 1;j++)
for (i = j + 1; i < 5;i++)
if (a[j]>a[i]){
t = a[j];
a[j] = a[i];
a[i] = t;
}
printf("The sorted numbers:
");
for (i = 0; i < 5; i++)
printf("%d ", a[i]);
system("pause");
return 0;
}
/*#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
void main(){
int a, b, c;
printf("请输入三个数字:");
scanf("%d,%d,%d", &a, &b, &c);
printf("%d,%d,%d", c, b , a);
system("pause");
return 0;
}*/
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
void main(){
int a[3];
int left = 0;
int right = 2;
for (left = 0; left <= 2; left++)
scanf("%d", &a[3]);
for (right = 2; right <= 0; right--)
printf("%d ", a[3]);
system("pause");
return 0;
}
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
int main(){
int a[10], b[10], i;
for (i = 0; i < 10; i++){
a[i] = i + 1;
printf("%d", a[i]);
}
for (i = 0; i < 10; i++){
b[i] = a[i];
printf("%d", b[i]);
}
system("pause");
return 0;
}
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
int main(){
int a[5], max, min, i, j, k;
for (i = 0; i < 5; i++)
scanf("%d", &a[i]);
max = min = a[0];
j = k = 0;
for (i = 0; i < 5; i++)
if (a[i] < min){
min = a[i];
j = i;
}
else if (a[i]>max){
max = a[i];
k = i;
}
a[j] = max;
a[k] = min;
for (i = 0; i < 5; i++)
printf("%5d", a[i]);
printf("
");
system("pause");
return 0;
}
define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
int main(){
int a[5], i, j, tmp;
printf("请输入五个数字
");
for (i = 0; i < 5; i++)
scanf("%d", &a[i]);
for (i = 1; i < 5; i++)
for (j = 0; j <5-i; j++)
if (a[j] >a[j+1]){
tmp = a[j];
a[j] = a[j+1];
a[j+1] = tmp;
}
printf("The result is:
");
for (i = 0; i < 5; i++)
printf("%d ", a[i]);
system("pause");
return 0;
}
以上是关于数组练习题10的主要内容,如果未能解决你的问题,请参考以下文章