ASSIGNMENT

O

osmium

CBFalconer said:
#include <stdio.h>

int main(void) {
int i, sum;

for (i = sum = 0; i < 20; i++)
if (!(i & 1)) sum += i;
printf ("Sum = %d\n", sum);
return 0;
}

but you can't enter that in your machine with your broken shift
key.

Before he enters anything, he should decide what the assignment means. I can
think of no rational reason for including the 0 and then excluding the 20
from the results. This is the epitome of wishy-washy.
 
H

Harald van Dijk

Richard said:
Richard Tobin said:
#include <stdio.h>

int total(int n)
{
[...]

Unfortunately this program does not conform to the C standard.

Um, why not? Looks fine to me.

total is reserved as an external identifier for use by the implementation.
 
U

user923005

Exactly. For all we know, one of these posters could in fact be
someone like that. Or maybe we have a sophomore who scored
high grades in his freshman year but has experienced a personal
tragedy in his first few weeks back and needs a small boost
while he's getting himself back in order. Many variables at
play.

This is analogous to:
A man is drowning, and you have a rope. Should you save him?
It might be Hitler or someone worse than Hitler. So don't save him.

Your argument is that you should do the wrong thing because it might
just be right in this instance.
Even though the probability that it is the most beneficial thing is
very near to zero.

The argument that this may be some desperate person who will lose
funding and lose face...
When the losing funding and losing face teach a lesson, it is probably
more valuable than bluffing your way forward.

When something bad happens, the bad thing can teach us a lesson the
same way as when a good thing happens.

In none of the hypothetical situations presented in this thread does
giving the person a finished homework problem seem like a good
solution to me.
 
K

Kenny McCormack

user923005 <[email protected]> continue to press home his theory that
help is not conducive to learning, leading up to:
....
When something bad happens, the bad thing can teach us a lesson the
same way as when a good thing happens.

In none of the hypothetical situations presented in this thread does
giving the person a finished homework problem seem like a good
solution to me.

Well, we are unlikely to change your mind then. Incidentally, I did
hear about this case, back in, I think it was 1993, where somebody's
mind/opinion *was* changed as a result of something they read in a
Usenet posting. Was quite the sensation, at the time.

It all boils down to probabilities, of course, and how you assess them.

All I can say is that the position we are advancing, is consistent with
today's "risk-free" approach to everything. I.e., the idea that the
world should made as close to risk-free as possible. Which does boil
down to "getting people through", regardless of the long term effects.

None of what I have written in this post should be taken to in any way
contradict or supercede what I have written in previous posts.
 
O

osmium

Harald van D?k said:
total is reserved as an external identifier for use by the implementation.

Is there a way to know this kind of esoterica without studying the standard?
Ideally a list of "gotchas".
 
L

Lew Pitcher

Think about the following scenario:
1) Somebody's almost failing a course, and subsequently flunking
out of school, and they're getting desperate (and face it,
you'd have to be pretty desperate to be looking for help in
this loony place known as CLC).

So, what sort of help are they looking for, and what sort of help do they
need? I've been a professional programmer (now retired), and have taken
said courses; I'm pretty sure of what it takes to learn from (or
conversely, flunk) those courses.

You know the "give a man a fish" saying? Well, ISTM that it applies to this
situation as well, but even more so. It is secondary that the OP doesn't
know how to solve a simple problem with elementary C code. The *primary*
problem is that the OP doesn't know how to "think like a programmer". Once
he conquers /that/ step, it becomes trivial to learn and use /any/
programming language to solve programming problems.

So, What should we (in CLC) do for such questions? Should we ignore them?
Should we give them the (useless) answer to their question? (Useless,
because without the "programmer mindset", the "answer" does not solve their
real problem). Do we show them their failings? Do we carp about other
posters? Or, do we try to teach them to "think like a programmer" so that
they can learn?
2) Said person's parents are threatening to cut off funding if
said person flunks out. Also comments to the effect of
bringing shame on the family...

If the person posts an obvious homework problem here for solution by others
(presumably, so that s/he can claim unearned credit for the solution), then
s/he has /already/ brought shame on themselves and on their family. If I
were taken to judgments, I would say that they were cheats and liars, and
lazy (or at least inattentive) to boot. Thankfully, I'm not taken to
judgments.
3) Said person looks for help on CLC and gets the usual
treatment, and subsequently kills himself.

I seriously doubt it. But then again, if someone is so off-centre that they
commit suicide because someone here gave them flack for posting a homework
problem, it is likely that they are already on the suicide track,
and /anything/ could set them off.
You want that on your conscience?

Think of it as evolution in action.

HTH
--
Lew Pitcher

Master Codewright & JOAT-in-training | Registered Linux User #112576
http://pitcher.digitalfreehold.ca/ | GPG public key available by request
---------- Slackware - Because I know what I'm doing. ------
 
F

Falcon Kirtaran

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Sure, but you won't learn anything from it.


/***********************/
#include <stdio.h>

int sum(int input);

int main(void)
{
int a;
a = sum(20);
printf("The sum is: %d\n", a);
return 0;
}

int sum(int input)
{
int temp = input / 2;
return temp * (temp + 1);
}

/***********************/

Heh. He is very fortunate I am not the one grading this.

- --
- --Falcon Darkstar Christopher Momot
- --
- --OpenPGP: (7902:4457) 9282:A431

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.9 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iQIcBAEBAgAGBQJJ81RXAAoJEKmxP9YxEE4rR7UP/ju7rue8WgCk9CpLPWJD3BnU
PN3JXzY1Xt6gLRc8cei80zAxMP8Ot8hp8N+Q8kzAJWKuGtXrZ5dnJSHJ5siHSg3R
LvjLA2048eN/NhwWhBHbb6HeePiaAIq6hiM55ITbC/DQ+zYPM1FEnT6asC2DLxtY
xjdWqlbEIZu4QxtI0t2Ku51AUNSaZUFRXk0r/f6yBNngtoqxYN8cv4FyFUV3a88J
6aSKghEQAStWnOITTC1kK6UPu/i7y6y7X/vqocaA02YQKJyNRv2HNz8nWOzJJCT2
fOiCvz812v2/W/5y79KgGZBckeRp0uCqICW1/6PYcEmNdsAQ2Vkn9tBkQVRz7mDG
FbWAW12frJCfSwALtqtpM5inMimFBzESvtepUXMAMangxUP3dNToDCzTT0NJy+Em
3baV4eHhTkrB1EknZeIwRZMNTgamIFwEtOWgSnNVU1ACqBFyCXYSc1VnRqd6PSTk
U6S4xoVV438Yq7dlQW0+IO7K+OFZZHrz/usDg60Ld7kB6BkDELywKQxY/467kT3C
k1CFO1CS9lidTUU4t5pXegfHESXE/HwaK2LXlfRAWC/uO7eUszKSha+j3tgPDRNk
DkEqICO4r5gcmTtrTOjEMer1ZNBYwL4R7Ls79jh9I5DEJ6WE8Vs1xSW6xWIo2tB+
b25wnukGv5lQsdWIpI1s
=ZkDT
-----END PGP SIGNATURE-----
 
K

Keith Thompson

user923005 said:
Kenny McCormack wrote:
[snip]

This is analogous to:
A man is drowning, and you have a rope. Should you save him?
It might be Hitler or someone worse than Hitler. So don't save him.
[...]

Why are you feeding the trolls?
 
F

Falcon Kirtaran

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

COULD YOU PLEASE SOLVE THE FOLLOWING QUESTION.

WRITE A PROGRAM IN C THAT WILL CALCULATE THE SUM OF EVEN NUMBERS FROM
0 TO 20?

Absolutely, but I hope it doesn't need to be standard compliant. In
fact, you might have to run it through a C++ compiler to get object code.

/*********/

#include <stdio.h>
#include <limits.h>
#include <stdlib.h>

typedef struct qnode qnode;
typedef struct queue queue;

struct qnode {
unsigned long long int v;
qnode* next;
};

struct queue {
qnode* first;
qnode* last;

qnode* pop() {
qnode*r=first;first=first?first->next:INT_MAX>>(sizeof(int)*8);return r; };

void push(struct qnode* t) { last?last->next=t,last:last=t;
first?first:first=t; };
};

unsigned long long int t(unsigned long long int q) { return q==(440>>2); };

int main() {
queue q;
q.first = 0;
q.last = 0;
qnode* nn = (qnode*)malloc(sizeof(qnode));
nn->v=0;
q.push(nn);

while (nn=q.pop()) {
if (t(nn->v)) {printf("%Lu\n", nn->v); free(nn); break;};
qnode* f = nn;
for (int i=0;i<1000;i++) { nn=(qnode*)malloc(sizeof(qnode)); nn->v =
f->v + i; q.push(nn); };
free(f);
};

while (nn=q.pop()) free(nn);

return UINT_MAX>>32;
};

/**********/

Of course, I have no idea if this is right, terminates, or even
compiles, but it looks pretty.

- --
- --Falcon Darkstar Christopher Momot
- --
- --OpenPGP: (7902:4457) 9282:A431

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.9 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iQIcBAEBAgAGBQJJ818iAAoJEKmxP9YxEE4r+28P/3SIKrc41gAV6SEnUgeajx77
OcXE8awVbg4rZ6qyK6RPY4oHdWCjbZxoAllazakj6xleDZR8YfC3XXXU4wUUkU27
nyWS/vgqw8Obk5YqR7ef0aC68vu6yG7XPEP69E+4xrfBAscVk01qWlkfCBMLhCyg
QxRxv8klYG6HB7z7B9jVx9f5luu/2rJ86WuaSjmKJL/8rVuDgEDDZ1NFnTFb0V/l
rpB6SLf+JLFsOOR5JD4u07sJuV0orq2gae2agH7dDE8AExZo6BZwr9o0AsmniXLH
lYQR8eot2qSxVFbLUKOTlRqE0YJo5B6W8iWzrrrYlD4v/folGl8wRelw3s1SHY/L
Y9zbSiRb8zLbo/FjS5Z48v8NvcfnCBrkEgVoyaNITDlg7dfjUEBfuoE342eHZaDT
DOIv+ItAsbjDrPsx83GgjRobBDHgKh0DCfEC4ivo90VmEG6BD2jh777ivv9KqbtN
LdjtQ4DwYo38612llWVUwxeOde2GM/dz3BsohqLV2m9KDfhgsfN32tYdHsUFimBm
QOe2ci3OFVt0QfYOmLky4kzYn289Kyg/5ko20AwBtfdDJZFj6kpBVm4eutoL0ETK
wO0Elj3+Q9P4sqYM4tqurUcMs9StsA2onwCbfKPsoVKR3XYWqNx4RhsY6QEn0x1T
WdjBG7wKc6uS9xpoPfZi
=RbQ3
-----END PGP SIGNATURE-----
 
F

Falcon Kirtaran

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Well, two reasons that have nothing to do with the code. Any professor
at my school who would write an assignment question such as that would
most likely have marks assigned to the use of a loop. Also, 90% of the
time people write user-defined functions on their first C assignment,
there is cheating going on.

- --
- --Falcon Darkstar Christopher Momot
- --
- --OpenPGP: (7902:4457) 9282:A431

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.9 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iQIcBAEBAgAGBQJJ81/VAAoJEKmxP9YxEE4rJOAQAMNwEZkIm6ZUKFyX5aaH3cFF
lT40OCcpgLz+qrHkbmgOo5JTYg3OgNbrUeOQUqOE9wvN0tm5tEpqc9dwqNaceM1s
XiKT1H58ap3y7vJ+1jTwqkB3gQ+wRIzDBO7RXGpyI8kxQFjS3lqpRAo2okjntAuT
Vv0lDaEJIPhIGk34izZ9LXlZAxxwqY1ZqZWcmVY6tf/tYCOsZbgCFqPqkBA94JqF
FJR9q3Y3dl5eEhLFPIFHdBWF4LObuvZKDqf/uQmzzGg6idFRQInh9JaqybvEWbZw
0wDEYJ6kta8Z5P993FrMxQ4awYYOMYGyacug1Wu9opx7a5KEEtlpB6h+qMWeR/VM
+nlB71vdLIa1gMFnDFY7bFpZggbhSgaRvRY/n7Tm+tjsrRiqhrqQT+Z+507EQdcm
ZDtswQD9EcQa9Rs2aTIT8Yiai8zAbeqK9Mc75pXmFqLsGnzbT0eqLEfXw3hEBd4K
rVSlcQwIwgnLUA5sOgGIUyYb6idty6pJRGZAs40+USTN2ClbxUri9KmuolEA2RhD
gBCjQ7nLc6T2Uwni03OmStueSRgsgu0CtUbnmxbbaWnjKy2EBwmXelycpj1dudP3
8RKpN42ZjVTWe9h4BieNYvbXNChEGtcuswHFEQUYOpqS3OdAYAgzG0tRpYKpUnYL
LbP8uphB86ZPUGD5d0h4
=/Kqw
-----END PGP SIGNATURE-----
 
F

Falcon Kirtaran

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Actually it's pretty ugly and wouldn't pass a first year code review.

This is true. They would also probably wonder why someone would use
breadth-first search for this.

- --
- --Falcon Darkstar Christopher Momot
- --
- --OpenPGP: (7902:4457) 9282:A431

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.9 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iQIcBAEBAgAGBQJJ82E9AAoJEKmxP9YxEE4rTtcQAJMBBco72ic29XAGp6rL62q4
ZYpl8nydwm4Y2IKE3qgGw2lBpXHwjx1A+YQwagBk5/P0sHNJQ/dftbhGvnVSej5R
7sILjgkiY+7EeClh+XuvV30tEhCzWo0WinmKcug0jHRhbLlIlr5bYjTOanEG2HZk
91bCvXVylC+O4k3tsr8jHCAH19930ZmVC5EM+BAvw1ZzGz6J/1iR6oZwFQeEBO/B
f15r/BZEKKZ16qCYNbKYuE2OJTjKkbXeWMluh7/Sz4Z2QITZf4hNNUnJ42gftB8f
2y/L4Z76wpC6NmOm9fAH36C4O7NEsaGrKVJSBxaXRI8OCdDPcEVYtmGHQRM0SIEf
WgwnVZmMxAMk8hDKEuL60qMIEqakBlfXLXI14yrQEQYM/aKnb7v48uZ3vq7gOOlm
H/Ah3qOahWn6AAxVYpj4REWjG/C38MgAetj8kUK3grENjToypOQfwToWOhadYtQh
H8Nj1CP0a9zvoVIXENPZDjpEPdldmGRB3kxJTntNcFyLc7/tqDcIxi+esdGLbVU4
tvr/nFNmqU+sfI8/VfKZmcNtgyogxh5pqTXy6iuuQKe1dgl8i1AYyNXLjlt0c6sa
dO672Xay7q3/2LCqGzoOLIa583PlJBzhPNWVn8B7gX+LS11CZk0KZPOnyf2k3e2c
4FcNLKP88tqssspxjZVx
=q0s2
-----END PGP SIGNATURE-----
 
K

Kenny McCormack

Han from China said:
That may be true in your personal experience. I note that much of
what you're saying may be true in your personal experience but
not in that of others. For many people in the world, life doesn't
reflect the Pollyanna-ish platitudes found in self-help books,
Hollywood dramas, and fortune cookies. For these people, there's
no such thing as fate, order, and teleology. Life is pretty much
a cruel crapshoot in which receiving an answer on a newsgroup
can swing one's fortune either way.

Excellently put. Very accurate and to the point. I wonder if Dan or
any of the others have even a snowball's chance of understanding what
you wrote, alas.

But, ya know, there is a real reason why these people don't like
to see people answering homework questions in their newsgroups, and its
got nothing to do with the feigned "Tough love" stance embodied in Dan's
posts. I wonder what it will take to get them to fess up to their real
motives.
 
R

Richard Tobin

total is reserved as an external identifier for use by the implementation.
[/QUOTE]
Is there a way to know this kind of esoterica without studying the standard?
Ideally a list of "gotchas".

It would be straightforward for compilers to (optionally) warn about
any reserved identifiers that they don't know to exist. Of course the
compiler could be out of sync with the library, but I think it would
be useful when writing "must conform as closely as possible" code.

-- Richard
 
H

Harald van Dijk

Richard said:

Why did you snip the attribution line for the below, which was present in
osmium's message?
It would be straightforward for compilers to (optionally) warn about
any reserved identifiers that they don't know to exist. Of course the
compiler could be out of sync with the library, but I think it would
be useful when writing "must conform as closely as possible" code.

The problem with that is that reserved identifiers that are unused by the
library are not a problem in practice. The reserved identifiers that are
used are a problem. I'm thinking of library header include guards, internal
functions in macro expansions, that sort of thing. You don't want the
compiler to warn about its own standard library macros, but you probably do
if user code uses the same names.
 
R

Richard Tobin

Harald van Dijk said:
Why did you snip the attribution line for the below, which was present in
osmium's message?

I only ever keep one level of attribution. I've discussed this here
before, and I'm not going through it again.
The problem with that is that reserved identifiers that are unused by the
library are not a problem in practice.

They're not a problem *now*, but they might be in the future when
new functions are added. Of course, this is unlikely, but if there's
any point reserving function names at all, then the same reasons
will presumably mean that at least some people want to know when
they're accidentally using them.

-- Richard
 
C

CBFalconer

Lew said:
First observation: this only counts even integers that range from
0 to 19. Was this intentional?

See below. Come to your own conclusion. You snipped the critical
piece about his inability to enter the program, due to his broken
shift key.
2nd observation: this seems a bit obfuscated to me (given that
the for() loop can take /any/ expression as the third expression).
A clearer "addition" solution might be

#include <stdio.h>
int main(void) {
int i, sum;

for (i = sum = 0; i <= 20; i = i + 2) /* even numbers from 0 to 20 */
sum = sum + i;
/* yes, I know about +=. But, does the OP? */
printf("Sum = %d\n",sum);
return 0;
}

You have to leave little traps for the cheating student.
 
C

CBFalconer

pete said:
CBFalconer said:
Harald said:
Richard Heathfield wrote:
Richard Tobin said:

#include <stdio.h>

int total(int n)
{
[...]

Unfortunately this program does not conform to the C standard.

Um, why not? Looks fine to me.

total is reserved as an external identifier for use by the
implementation.

Where is this specified?

N869
7.26
[#1]
7.26.2
[#1]

I find no such section in either n869 or n1256.
 
K

Keith Thompson

CBFalconer said:
pete said:
CBFalconer said:
Harald van D?k wrote: [...
total is reserved as an external identifier for use by the
implementation.

Where is this specified?

N869
7.26
[#1]
7.26.2
[#1]

I find no such section in either n869 or n1256.

Really? I see it in both; I wonder how you missed it.

n1256 7.26 Future library directions

7.26.2 Character handling <ctype.h>

Function names that begin with either is or to, and a lowercase
letter may be added to the declarations in the <ctype.h> header.
 
H

Harald van Dijk

I only ever keep one level of attribution. I've discussed this here
before, and I'm not going through it again.



They're not a problem *now*, but they might be in the future when
new functions are added.

And when those new functions are added, the compiler will no longer warn
about code that is now suddenly visibly broken?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,431
Messages
2,571,678
Members
48,796
Latest member
Greg L.

Latest Threads

Top