【C语言数组最简单题目】输入一组数.奇数放前面,偶数放后面

#include<stdio.h>
main()
{
int x,n[x],i;

printf("Please input the number of integers:");
scanf("%d",&i);

printf("Please input the integers:");
scanf("%d",n);

printf("The elements of the new array are:");

for(x=1;x<=i;x++)
{
if((n[x])%2==1)
printf("%d ",n[x]);
}
for(x=1;x<=i;x++)
{
if((n[x])%2==0)
printf("%d ",n[x]);
}

system("pause");
return 0;
}

初学者。。操蛋了。。
大神帮忙。。。

(1)int x,n[x];数组是不可以这么定义的,int n[10],数组的个数(也就是中括弧中的数)必须是已知数或类似于已知数的多项式,绝对不可以是变量。
(2)这题目是要输入很多个数组元素,scanf("%d",n);只能输入一个;因此,需要一个for循环来输入所要的数组元素;
温馨提示:答案为网友推荐,仅供参考
第1个回答  2013-12-11
#include<stdio.h>
main()
{
    int x,n[1024],i;

    printf("Please input the number of integers:");
    scanf("%d",&i);

    printf("Please input the integers:");
    for(x = 1; x <= i; x++)
        scanf("%d", &n[x]);

    printf("The elements of the new array are:");

    for(x=1; x<=i; x++)
    {
        if((n[x])%2==1)
            printf("%d ",n[x]);
    }
    for(x=1; x<=i; x++)
    {
        if((n[x])%2==0)
            printf("%d ",n[x]);
    }

    system("pause");
    return 0;
}

第2个回答  2013-12-11
这个确实挺乱的
相似回答