Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Code Golf

Return to Answer

save byte, add note about x=0
Source Link

C++ (gcc), (削除) 176 (削除ここまで) 137(削除) 137 (削除ここまで) 136 bytes

#import<cstdio>
int i;ff(){puts("#import<cstdio>\nf(unsigned x){");for(;printfint i;printf("x-%u?:puts(\"%s\");",i,i++&1?"even":"odd"),i;);puts("}");}

Try it online! Try it online!

The case when i = 0 comes last.

Uses -fwrapv flag for well-defined signed integer overflow wrapping (as opposed to the standard's undefined behaviour when overflowing).

Uses -fpermissive flag to suppress errors from defining f without a type

Thanks to Neil for suggesting changing printf to puts.

Borrows from the C (gcc) answer.

C++ (gcc), (削除) 176 (削除ここまで) 137 bytes

#import<cstdio>
int i;f(){puts("#import<cstdio>\nf(unsigned x){");for(;printf("x-%u?:puts(\"%s\");",i,i++&1?"even":"odd"),i;);puts("}");}

Try it online!

Uses -fwrapv flag for well-defined signed integer overflow wrapping (as opposed to the standard's undefined behaviour when overflowing).

Uses -fpermissive flag to suppress errors from defining f without a type

Thanks to Neil for suggesting changing printf to puts.

Borrows from the C (gcc) answer.

C++ (gcc), (削除) 176 (削除ここまで) (削除) 137 (削除ここまで) 136 bytes

#import<cstdio>
f(){puts("#import<cstdio>\nf(unsigned x){");for(int i;printf("x-%u?:puts(\"%s\");",i,i++&1?"even":"odd"),i;);puts("}");}

Try it online!

The case when i = 0 comes last.

Uses -fwrapv flag for well-defined signed integer overflow wrapping (as opposed to the standard's undefined behaviour when overflowing).

Uses -fpermissive flag to suppress errors from defining f without a type

Thanks to Neil for suggesting changing printf to puts.

Borrows from the C (gcc) answer.

-many bytes
Source Link

C++ (gcc), 176(削除) 176 (削除ここまで) 137 bytes

#import<iostream>#import<cstdio>
int64_tint i;maini;f(){printfputs("#import<iostream>\nmain"#import<cstdio>\nf(unsigned x){int64_t x;std::cin>>x;"");do printf;for("if;printf(x==%ld)printf"x-%u?:puts(\"%s\");",i,i&1i++&1?"odd":"even":"odd");while(++i,i;);printf;puts("}");}

Try it online!

Try with i<10 Try it online!

Uses -fwrapv flag for well-defined signed integer overflow wrapping (as opposed to the standard's undefined behaviour when overflowing).

Uses -fpermissive flag to suppress errors from defining f without a type

Thanks to Neil for suggesting changing printf to puts.

Borrows from the C (gcc) answer .

C++ (gcc), 176 bytes

#import<iostream>
int64_t i;main(){printf("#import<iostream>\nmain(){int64_t x;std::cin>>x;");do printf("if(x==%ld)printf(\"%s\");",i,i&1?"odd":"even");while(++i);printf("}");}

Try it online!

Try with i<10

Uses -fwrapv flag for well-defined signed integer overflow wrapping (as opposed to the standard's undefined behaviour when overflowing)

C++ (gcc), (削除) 176 (削除ここまで) 137 bytes

#import<cstdio>
int i;f(){puts("#import<cstdio>\nf(unsigned x){");for(;printf("x-%u?:puts(\"%s\");",i,i++&1?"even":"odd"),i;);puts("}");}

Try it online!

Uses -fwrapv flag for well-defined signed integer overflow wrapping (as opposed to the standard's undefined behaviour when overflowing).

Uses -fpermissive flag to suppress errors from defining f without a type

Thanks to Neil for suggesting changing printf to puts.

Borrows from the C (gcc) answer .

Source Link

C++ (gcc), 176 bytes

#import<iostream>
int64_t i;main(){printf("#import<iostream>\nmain(){int64_t x;std::cin>>x;");do printf("if(x==%ld)printf(\"%s\");",i,i&1?"odd":"even");while(++i);printf("}");}

Try it online!

Try with i<10

Uses -fwrapv flag for well-defined signed integer overflow wrapping (as opposed to the standard's undefined behaviour when overflowing)

AltStyle によって変換されたページ (->オリジナル) /