Remove even numbers from array in c

后端 未结 2 2015
野性不改
野性不改 2021-01-29 11:36

Hello i\'m trying for about 2 hours to create a program which will remove even numbers from a dinamyc allocated array(with malloc)in c.Can somebody help me with some tips or cre

2条回答
  •  醉话见心
    2021-01-29 12:09

    There are some things which you need to check before you try to code something, but I see that there is no code which you showed use.

    SO is not a tutorial site, so this means that you should show us some code which actually does compile and ask here if there are some problems with that code.

    Any way until than, this code should give you an Idea about how to check if a Number is odd or even:

    #include
    #include
    
    int main(void){
        int n;
    
        printf("Enter an integer:>  ");
        if((scanf("%d", &n)) != 1){
            printf("Error, Fix it!\n");
            exit(1);
        }
    
        if (n%2 == 0){
            printf("Even\n");
        }else{
            printf("Odd\n");
        }
    
        return 0;
    }
    

    The whole story here is not about checking if Numbers inside an Array are odd or even, is about to find a way to check if a number is odd or even and only then you should check if inside that array there are odd or even numbers. I hope you understand my point.

提交回复
热议问题