#if i gave a number maybe = 234, i want the computer go 1 by 1 and tell me if its even or odd

33 messages ยท Page 1 of 1 (latest)

spare shoreBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.

marble fable
#
#include <iostream>
using namespace std;

int main(){
    int n, even, odd;
    int arr[n];
    cin >> n;

    for (int i = 0; i < arr[n]; i++)
    {
        if ()
        {
            
        }
        
    }
    

    cout << even << endl;
    cout << odd ;
}
#

thats all i got

#

but how to do it

#

i really dont know

crimson root
#

that's VLA ๐Ÿ’€

spare shoreBOT
#
What Is a VLA And Why Is It 'Bad'?

A Variable Length Array (VLA)
is an array where the size is not constant and depends on a variable.

VLAs have poor compiler support and can lead to inefficient code.
The core issue with VLAs is that the compiler doesn't know the size of the stack frame.
Without warning flags like -Wvla (Note: -Wvla is not turned on by -Wall nor any other warning
flag) it can be easy to create a VLA by accident, even in C++ with some compilers.

Compiler Support

โœ… available since C99
โ›” not available in C++ at all
โ›” was never supported by MSVC
โš  optional feature since C11
โš  supported as non-standard extension by GCC, clang

crimson root
#

but i guess we can just ignore the fact that you shouldn't use it, since this is more about algorithm

marble fable
#

oh

#

i shouldn't use an array?

crimson root
#

i mean rn you're creating n sized array

#

I don't know how to give you a hint without giving it all away

crimson root
#

I would use % operator do you know what it does ?

marble fable
#

mhm

#

ik the part

#

where

#

n % 2 == 0

#

but

#

if i want the whole

#

number

#

but it goes like

#

digit to digit

#

123
odd = 2
even = 1

#

yk?

#

god c++ is confusing

crimson root
#

you will get used to syntax quickly

marble fable
crimson root
#

it's good to work on some specific example first
say we get 279
279 % 2 tells us whether the last (rightmost) digit is even or odd
now after doing this we need to get to the next digit so from 279 we need 27

spare shoreBOT
#

@marble fable

Please Do Not Delete Posts!

Please don't delete forum posts. They can be helpful to refer to later and other members can learn from them. You can use !solved to close a post and mark it as solved.

marble fable
#

!solved