This challenge is intended to utilize the C language ( as a means of solving a problem. However, language-specific challenges are generally discouraged on CG.

learn more… | top users | synonyms

-1
votes
1answer
222 views

Smallest C code to Crash an Operating System? [duplicate]

A shortest C program, that can crash the Operating system, either on a Windows or a Linux PC... Rules: The code is to be developed in C language, but it may use other api, specific to linux or ...
7
votes
1answer
247 views

Implement an IEEE 754 64-bit binary floating point number through integer manipulation

(I've tagged the question "C" for the time being, but if you're aware of another language that supports unions, you can also use that.) Your task is to build the four standard mathematical operators ...
0
votes
1answer
107 views

Shortest conditional to run a specific statement: C code golf

Currently I have the code (expanded for your benefit): <number> != <number> ? printf("|\\"); : <number>; The idea here, is to do this condition in the least number of characters. ...
5
votes
12answers
882 views

print 1 to 100 without using recursion and conditions

can we print 1 to 100 without using any if conditions and loops in c&c++? Conditon: main point is you must not use recursion...and doesnt hardcode code in it for e.g print(1 2 3..etc);
9
votes
7answers
471 views

C: replace AES FIPS-197 SubBytes table by constant-time code

In FIPS-197 (the Advanced Encryption Standard, known as AES), it is made heavy use of SubBytes, which could be implemented as unsigned char SubBytes(unsigned char x) { static const unsigned char ...
5
votes
3answers
632 views

Create a C program that takes the longest period of time to compile in gcc

Create a short C program that takes an absurdly long time to compile with gcc. Entries will be scored by timing the compilation then subtracting the reference program's compile time. Rules Any C ...
3
votes
4answers
596 views

RPN calculator without pointers

Me and some other students were at a bar discussing programming languages, in particular the C programming language. At some point a first year student said he didn't need no damn pointers. Another ...
3
votes
3answers
808 views

The shortest code to tell if a number is even or odd

One of my colleagues proposed us a challenge: to write the shortest C/C++ program to determine if a number is even or odd. These are the requirements: Get a number from keyboard, at run-time (not ...
2
votes
3answers
329 views

m3ph1st0s's programming puzzle 4 (C/C++): “3-way swap”

My last puzzle has generated some confusion and controversy so I decided to give up, for now, on those "replace one character"-type puzzles. Hope this 4th puzzle will redeem myself after all the ...
7
votes
2answers
440 views

m3ph1st0s's programming puzzle 3 (C): “Easy bug”

This is the 3rd of my series of C/C++ puzzles; in case you missed the first 2 they are here: (1) m3ph1st0s's programming puzzle 1 (C++) (2) m3ph1st0s's programming puzzle 2 (C++): "Call ...
43
votes
69answers
8k views

When does (x == x+2)?

The challenge: Define x in such a way that the expression (x == x+2) would evaluate to true. I tagged the question with C, but answers in other languages are welcome, as long as they're creative or ...
0
votes
11answers
544 views

Code-golf: square of the number of ones

I'm solving problem: in file "a.in" given the number N - length of the number consists of ones. Need to gets square of it, and put this in file "a.out". This is my shortest solution(150 bytes): char ...
7
votes
12answers
884 views

“First time” test

What is the shortest C expression that is defined to evaluated to false the first time and true for every time after that: Reference implementation: bool b = false; // you get this for free. (b ? ...
14
votes
5answers
638 views

Write the prettiest bytebeat composition

Bytebeat is a style of music one can compose by writing a simple C program that's output is piped to aplay or /dev/dsp. ...
0
votes
0answers
150 views

Why declaring variables like main(a,b) is legal? [closed]

main(a,b){ } declares two integers... first of all... Why I don't have to specify type? How many ints I can declare in this way? Another question is, why I can also do that: a,b;main(){...}
3
votes
2answers
291 views

HangOver ACM problem!

there is only one rule: get accept for this problem http://acm.ut.ac.ir/sc/problemset/view/1032! to submit your code, you need to create an account(if you don't want to do so, just post your code ...
6
votes
2answers
338 views

Which Numbers Would Crash this Function?

Which values of x and y will cause a crash with some C compilers? int f(int x, int y) { return (y==0) ? 0 : (x/y); }
5
votes
5answers
326 views

Shortest code that return SIGSEGV among the given languages

I come across a question in a coding competion "write a code that returns SIGSEGV(Segmentation fault ) " . Points were given on the basis of length of code. The prgramming languages available ...
2
votes
2answers
345 views

Fastest C/C++ comparison function for an opaque field containing doubles

Description: Write the fastest comparison function for an opaque field containing a double. Here is my example: // Three-way comparison function: // if a < b: negative result // if a > b: ...
0
votes
0answers
224 views

Linkedlist in C - Debug [closed]

This is not exactly a code development challenge but a code debugging one. I have a C code which is essentially a code to test different operations on a linked list. It contains 2 source files main.c ...
-2
votes
5answers
860 views

C: Output “tomorrow's date”

I'm a code golf novice, but I'm eager to give it a go. My challenge is: Write the shortest program in C which takes in a date D as input and outputs the date D + 1 day Rules: program must compile ...
19
votes
16answers
2k views

Tips for golfing in C

What general tips do you have for golfing in C? I'm looking for ideas that can be applied to code golf problems in general that are at least somewhat specific to C (e.g. "remove comments" is not an ...
-1
votes
1answer
1k views

Poisson random number generator

What is the shortest function (implemented in C) that will return a random draw from a Poisson distribution (given the mean or λ parameter)? int random_poisson(double lambda);