输入一个数组长度,动态创建数组,所有元素随机生成,输出元素中最大值

来源:互联网 发布:调查问卷数据怎么统计 编辑:程序博客网 时间:2024/05/15 22:46
int n = 0;
    printf("输入数组长度:");
    scanf("%d", &n);
    
    int *temp = malloc(n * 4);
    for (int i = 0; i < n; i++) {
        temp[i] = arc4random()%51;
        printf("%d ", temp[i]);
    }
    int x = temp[0];
    for (int i = 0; i < n; i++) {
        if (x < temp[i]) {
            x = temp[i];
        }
    }
    
    printf("\n%d\n", x);
    
    
    
    
    free(temp);
    temp = NULL;

0 0