Task 1 incorrect sample for C

Back to General discussions forum

Vadim Tukaev     2015-10-11 18:25:34

Task 1 "Sum A B" have incorrect sample! I am amazed that no one noticed this error until now.

#include <stdio.h>

int main(void) {
    int a, b;
    scanf("%d %d", &a, &b);
    printf("%d\n", a + b);
    return 0;
}

According to the standard of C language, type "int" is not obliged to hold numbers above 32767. You must use "long" here.

P.S. C is a language designed for pedants, nerds and perfectionists.

Quandray     2015-10-11 19:07:35
User avatar

These days, I reckon you'll have trouble finding a C compiler that holds an int in less than 4 bytes. My compiler holds a short in 2 bytes, an int and a long in 4 bytes and a long long in 8 bytes.

Rodion (admin)     2015-10-11 19:38:13
User avatar

Huh! Interesting point! Thank you :)

My opinion is exactly what Quandray says, truly C compilers with 16-bit ints are used now in industry only for small MCU programming!

But I also do know that some students still use Borland C/C++ which I remember from the times I myself was learning C...

So I'll think a bit - what is better, change the sample to long or perhaps to reduce the range of the numbers generated for the first task (because it is probaby not very important).

Vadim Tukaev     2015-10-12 07:04:46

I think it is better to reduce numbers to be able to solve this problem in Brainfuck too.

Rodion (admin)     2015-10-12 07:37:32
User avatar

Yeah! That is also good point!

So I changed them to not exceed 16000, hence the sum should be suitable for 16-bit signed int!

Thank you for the insight!

Please login and solve 5 problems to be able to post at forum