下面是一个示例代码:

#include <stdio.h>

void Input(int a[], int n) {
    printf("请输入%d个整数:\n", n);
    for (int i = 0; i < n; i++) {
        scanf("%d", &a[i]);
    }
}

int main() {
    int a[100], n;
    printf("请输入数组大小n:");
    scanf("%d", &n);
    Input(a, n);
    printf("输入的数组为:");
    for (int i = 0; i < n; i++) {
        printf("%d ", a[i]);
    }
    printf("\n");
    return 0;
}

函数Input接收两个参数:一个是整型数组a,一个是整型变量n,表示输入的整数个数。函数中使用for循环逐个输入整数,并将其存入数组a中。主函数中先输入数组大小n,然后调用函数Input输入整数,最后输出输入的数组

c语言1编写函数Input实现输入n个整数存入一维数组a;

原文地址: https://www.cveoy.top/t/topic/emPG 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录