作业7

1.

#include<stdio.h>
int main()
{int a,b,c,max;
scanf("%d %d %d",&a,&b,&c);
max=a;
if(b>max)max=b;
if(c>max)max=c;
printf("max=%d\n",max);
return 0;
}
2.
#include <stdio.h>
int main(void)
{
int a[10], max, min, temp;
int i, j;
printf("please input 10 number:\n");
for( i = 0; i < 10; i++)
scanf("%d", a++); # a代表数组a的第一个参数的地址,所以无需要&
max = a[0];
min = a[0];
for( i = 0; i < 10; i++){ #判断最大值所在的位置
if(a[i] > max){
max = a[i];
j = i;
}
}
temp = a[j]; #把最大值与最后一位交换
a[j] = a[9];
a[9] = temp;
for( i = 0; i < 10; i++){ #判断最小一位的位置
if(a[i] < min){
min = a[i];
j = i;
}
}
temp = a[j]; #交换第一位和最小值
a[j] = a[0];
a[0] = temp;
for(i = 0; i < 10; i++)
printf("% ", a[i]);
}
3.
#include<stdio.h>
void str_copy(char *str1, char *str2)  // 字符串复制函数
    while(*str1++ = *str2++);  // 将字符串str2中的每个字符逐个复制到str1中,直到遇到字符串结束字符'\0'
}
void main()
{
    char s1[] = "abcd";
    char s2[5];
    str_copy(s2, s1);  // 将字符串s1复制到s2中
    printf("%s", s2);  // 输出字符串s2,输出结果为abcd
}
posted @ 2016-12-15 10:05  160809214赵子晨  阅读(114)  评论(1编辑  收藏  举报