#include <stdio.h>//求第二大的数
int main(int argc, const char *argv[])
{
int i,j;
int arr[5];
int temp;
int max2 = 0;
for(i=0;i<5;i++){
printf("arr[%d] = ",i);
scanf("%d",&arr[i]);
}
for(i=0;i<5;i++){
for(j=0;j<5-i;j++){
if(arr[j]>arr[j+1]){
temp = arr[j];
arr[j] = arr[j+1];
arr[j+1] = temp;
}
}
}
printf("第二大的值是arr[%d] = %d\n",i-2,arr[3]);
return 0;
}
#include <stdio.h>//输出删除空格后的字符串
int main(int argc, const char *argv[])
{
int i = 0;
int j = 0;
char s[128];
printf("输入字符串:");
s[i]= getchar();
while(s[i]!='\n'){
if(s[i]!=' '){
s[j] = s[i];
i++;
j++;
}
s[i] = getchar();
}
printf("删除空格后的字符串为:");
puts(s);
return 0;
}
#include <stdio.h>//冒泡排序10个学生的成绩
int main(int argc, const char *argv[])
{
int i,j,temp;
int s[10] = {0};
for(i=0;i<10;i++){
printf("第%d个成绩:",i+1);
scanf("%d",&s[i]);
}
for(i=0;i<10;i++){
for(j=0;j<10-i;j++){
if(s[j]>s[j+1]){
temp = s[j];
s[j] = s[j+1];
s[j+1] = temp;
}
}
}
printf("成绩低到高为:");
for(i=0;i<10;i++)
printf("%d ",s[i]);
return 0;
}