zoukankan      html  css  js  c++  java
  • 作业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 ",max);
    return 0;
    }
    2.
    #include <stdio.h>
    int main(void)
    {
    int a[10], max, min, temp;
    int i, j;
    printf("please input 10 number: ");
    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中,直到遇到字符串结束字符''
    }
    void main()
    {
        char s1[] = "abcd";
        char s2[5];
        str_copy(s2, s1);  // 将字符串s1复制到s2中
        printf("%s", s2);  // 输出字符串s2,输出结果为abcd
    }
  • 相关阅读:
    1094. Car Pooling
    121. Best Time to Buy and Sell Stock
    58. Length of Last Word
    510. Inorder Successor in BST II
    198. House Robber
    57. Insert Interval
    15. 3Sum java solutions
    79. Word Search java solutions
    80. Remove Duplicates from Sorted Array II java solutions
    34. Search for a Range java solutions
  • 原文地址:https://www.cnblogs.com/zzc214/p/6182107.html
Copyright © 2011-2022 走看看