Closed. This question is off-topic。它当前不接受答案。
                            
                        
                    
                
                            
                                
                
                        
                            
                        
                    
                        
                            想改善这个问题吗? Update the question,因此它是on-topic,用于堆栈溢出。
                        
                        6年前关闭。
                                                                                            
                
        
所以基本上,我希望用户输入他们的家庭大小,并根据他们的大小,我想询问他们的年龄与家庭成员的年龄一样多(因此输入取决于他们)。
现在,我想将年龄输入作为数组列表。例如,如果他们是其中的2个,那么我想两次询问他们的年龄并将其保存为

scanf("%d",age[0]);
scanf(%d",age[1]);


在这里我可以想到C代码:

   #include <stdio.h>
    int main(int n, int age[0]){
        printf("enter your family number:");
        scanf("%d", n);
    }

    for(i=1; i>=n; i++){
        printf("Can I have your family's age one by one:");
        scanf("%d",&age[i]);
    }

最佳答案

#include <stdio.h>

int main(void){
    int n;
    printf("enter your family number:");
    scanf("%d", &n);

    int i, age[n];
    for(i=0; i<n; ++i){
        printf("Can I have your family's age one by one:");
        scanf("%d", &age[i]);
    }
    return 0;
}

关于c - 我是c语言的新手,我需要数组的帮助。,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/21279484/

10-11 22:59
查看更多