Tagged Questions

This challenge is related to the C language. Note that challenges that require the answers to be in a specific language are generally discouraged.

learn more… | top users | synonyms

-5
votes
0answers
30 views

I can't get to embed the code I made [on hold]

I have two pieces of code I wrote in C. I want to ember the 1st code inside the second where I said. How can I do it without get errors? 1st code #include <errno.h> ...
3
votes
3answers
194 views

Preprocessing primality

The challenge: Given an integer N, 1 < N < 2³¹, write code that uses the C preprocessor to determine whether N is prime, and produces a "Hello world" program if N is prime, or an error ...
12
votes
14answers
3k views

Compare two integers in C or C++ without comparison operators

Produce the shortest program which takes two signed integers as input (through stdin or as arguments) and displays 3 different outputs depending upon whether the first number is (1) greater than, (2) ...
7
votes
1answer
266 views

Smallest Lua table copy

So I really like to mess with tables and shallow and deep copies and I can do it in 239 chars! I wonder if there's a shorter way to do it... Rules: It must be done in less than 239 chars. You must ...
7
votes
0answers
539 views

X greater than 3 with at least 2 difference between X and Y

I am trying to golf down some C++. Is it possible to make this condition shorter? X > 3 & X - Y > 1 (Apart from removing whitespace, of course.) So, X is at least 4 but X >= Y + 2. X ...
18
votes
4answers
1k views

Add two numbers safely, in C

Everyone knows that C is a lovely, safe, high level programming language. However you, as a coder are set the following task. Write a program to add two numbers. Input: Two space separated ...
11
votes
14answers
1k views

Golfed+Fast sorting in C

[Latest update: benchmark program and preliminary resuls available, see below] So I want to test the speed/complexity tradeoff with a classic application: sorting. Write an ANSI C function that ...
14
votes
1answer
831 views

Create a C preprocessor

The goal is to create a preprocessor for the C language, as small as possible in terms of source code size in bytes, in your preferred language. Its input will be a C source file, and its output will ...
12
votes
7answers
1k views

C code indenter

Situation: You are a high school teacher, teaching your computing class how to write C programs. However, since it is just the beginning of the term, you haven't taught them about the importance of ...
8
votes
8answers
1k views

Shortest C \ C++ function to generate -1, 0 ,1

Let a function receive two integers i and j between 0 and 3, it should return the value in position (i,j) in the following 2D array: 1, 0, -1, 0 1, 0, -1, 0 0, 1, 0, -1 0, -1, 0, 1 Shortest ...
-8
votes
2answers
541 views

Algorithm to find one unique number in one million and 1 numbers [closed]

I have been asked this question in an interview. In 1 million and 1 numbers, all the numbers having the duplicate except only one number. How to find that one number ? I got an idea to use EXOR gate ...
0
votes
0answers
98 views

reversion of string in c [duplicate]

In python reversing of string is as easy as: string[::-1] But not very same in c. This is the code I am using to reverse integers in C: #include <stdio.h> int main(int argc, char *argv[]) { ...
-4
votes
3answers
416 views

C without the braces [closed]

My challenge is language-specific, but needs a lot of creativity: write a valid C program with only one pair of braces {} and none of the keywords if, for, while (all checked after preprocessing, and ...
4
votes
6answers
831 views

Make FizzBuzz using only preprocessor directives

I have a source file here: #include <FizzBuzz.h> fizzbuzz And I want to make "fizzbuzz" turn into a FizzBuzz program solely through the preprocessor. Your task is to write a FizzBuzz.h that ...
3
votes
1answer
532 views

Flip the commented-out code [closed]

This puzzle works for any programming language that has the same // single-line and /* ... */ multi-line comments that C++, C# and Java do. You are debugging an application. You find a fishy block of ...
0
votes
1answer
3k 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 ...
12
votes
1answer
539 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
2answers
242 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. ...
10
votes
20answers
3k 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);
11
votes
7answers
914 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 ...
15
votes
3answers
3k 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 ...
5
votes
4answers
1k 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 ...
5
votes
3answers
2k 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 ...
3
votes
3answers
536 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 ...
11
votes
5answers
1k 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 ...
1
vote
11answers
652 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
963 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 ? ...
20
votes
5answers
1k 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. ...
4
votes
2answers
448 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 ...
10
votes
2answers
534 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); }
6
votes
7answers
830 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 ...
3
votes
2answers
545 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: ...
3
votes
5answers
2k 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 ...
44
votes
21answers
4k 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 ...
2
votes
1answer
2k 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);