Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

ASSIGNMENT

22 views
Skip to first unread message

azo...@gmail.com

unread,
Apr 24, 2009, 8:56:24 AM4/24/09
to
COULD YOU PLEASE SOLVE THE FOLLOWING QUESTION.

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

Carl

unread,
Apr 24, 2009, 9:17:06 AM4/24/09
to

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);
}

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

luserXtrog

unread,
Apr 24, 2009, 9:22:01 AM4/24/09
to

Yes, I could.

--
lxt

osmium

unread,
Apr 24, 2009, 9:36:16 AM4/24/09
to

<azo...@gmail.com> wrote:

Look into the use of a for statement and the modulo operator, which is
specified in C by the '%' symbol.

Typing in all upper case is considered bad form on Usenet. This IS Usenet.


mark.b...@googlemail.com

unread,
Apr 24, 2009, 9:36:44 AM4/24/09
to

In keeping with tradition...

#include <stdio.h>

typedef int IOI;
#define I 0
#define O 1
#define O1O printf

IOI IO1(IOI I01) {
return I01?I01 + IO1(I01-O):0;
}

IOI main(void) {
IOI I0I = IO1(0xa);
O1O("%d\n",I0I << (I0I>I));
}

Han from China

unread,
Apr 24, 2009, 9:38:22 AM4/24/09
to
azo...@gmail.com wrote:
> WRITE A PROGRAM IN C THAT WILL CALCULATE THE SUM OF EVEN NUMBERS FROM
> 0 TO 20?

Here you go. Nothing elegant or clever:

---------------------------------------------------------------------------
#include <stdio.h>

int main(void)
{
int i, sum = 0;

for(i = 2; i <= 20; i += 2)
sum += i;

printf("%d\n", sum);

return 0;
}

---------------------------------------------------------------------------

Any further problems, just let me know.

Yours,
Han from China

--
"Only entropy comes easy." -- Anton Chekhov

Lew Pitcher

unread,
Apr 24, 2009, 9:39:13 AM4/24/09
to
On April 24, 2009 08:56, in comp.lang.c, azo...@gmail.com (azo...@gmail.com)
wrote:

> COULD YOU PLEASE SOLVE THE FOLLOWING QUESTION.
>
> WRITE A PROGRAM IN C THAT WILL CALCULATE THE SUM OF EVEN NUMBERS FROM
> 0 TO 20?


OK, done.

Now, did you have a question about C?

<off-topic>
For what it's worth, you have apparently asked us to do your homework for
you. You were given this homework to help you understand the use of and
practice certain methods and facilities, and if we do your homework for
you, it defeats the purpose of the homework.

We are not a "homework help line", but if you post what you've done so far,
we can help you by making suggestions as to how to fix what you've done.

/I/ will go further than that, though. I will tell you how to write the
program you've asked us about.

First off, don't even think of C.

Get a sheet of paper, and write down all the even numbers between 0 and 20.
Add them up, and write down the total.
Study this for a moment, remembering exactly how you worked out the
solution. How did you pick "even numbers"? How did you know where to start?
How did you know where to stop?

Now, on another sheet of paper, write down the steps that you took. Start
with how you decided where to start. Include how you decided to pick even
numbers, how you added the numbers together, and end with how you decided
to stop.

Once you can /clearly/ explain how to solve the problem /on paper/, you can
then look for programming language tools that you can use to follow that
explanation. Use these tools, and write a short C program that does what
you did manually. Then try it, and see if it gets the same answer you got
when you did it manually. If it doesn't work, show us what you did, and we
can help get you back on track.

A suggestion/hint for this stage: the C "for()" construct has four parts:
1) a part that tells it where to start,
2) a part that tells it how much to change by,
3) a part that tells it where to stop, and
4) a part that tells it what to do at each step.
That sounds a lot like the things I asked you to remember from before,
doesn't it?

</off-topic>


--
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. ------


Mark Bluemel

unread,
Apr 24, 2009, 9:46:18 AM4/24/09
to
Lew Pitcher wrote:
> On April 24, 2009 08:56, in comp.lang.c, azo...@gmail.com (azo...@gmail.com)
> wrote:
>
>> COULD YOU PLEASE SOLVE THE FOLLOWING QUESTION.
>>
>> WRITE A PROGRAM IN C THAT WILL CALCULATE THE SUM OF EVEN NUMBERS FROM
>> 0 TO 20?
...

> We are not a "homework help line", but if you post what you've done so far,
> we can help you by making suggestions as to how to fix what you've done.
>
> /I/ will go further than that, though. I will tell you how to write the
> program you've asked us about.
>
> First off, don't even think of C.
>
Think about mathematics. What have you learnt about sums of series (have
you learnt anything about them)? Can you apply this to the problem in hand?

Hint: If it were all the even numbers from 2 to 10,000,000 you wouldn't
even consider doing individual addition would you?

Dik T. Winter

unread,
Apr 24, 2009, 9:41:00 AM4/24/09
to

int main(void) {
int sum;

sum = 0+2+4+6+8+10+12+14+16+18+20;
}
--
dik t. winter, cwi, science park 123, 1098 xg amsterdam, nederland, +31205924131
home: bovenover 215, 1025 jn amsterdam, nederland; http://www.cwi.nl/~dik/

Lew Pitcher

unread,
Apr 24, 2009, 9:53:24 AM4/24/09
to
On April 24, 2009 09:46, in comp.lang.c, Mark Bluemel
(mark_b...@pobox.com) wrote:

Of course.

OTOH, an obvious simple homework problem, and an OP who cant solve it,
points to a "beginners" course in C. Homework is given for a reason, and a
C-language homework problem of such a simple nature isn't likely meant to
teach how to apply lateral thinking to mathematical problems. Instead, it
is likely to be re-enforcing the basics of the C language.

So, a lateral reinterpretation of the mathematics could be the solution to
the problem as stated. But then again, so could a simple for() loop which
constructs the solution using simple arithmetic. And the for() loop is more
likely to be what the homework is all about, don't you think?

Carl

unread,
Apr 24, 2009, 9:50:47 AM4/24/09
to


The thought had just occurred to me that he probably needs to use a for
loop in this assignment. Sorry about the confusion. Here is the new
fragment:

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

int main(void)
{
unsigned char nti[2] = {(~0["\355"]^7)};
for(*(nti+1)&=0;--(*nti);nti[1]+= (nti[0]&1)?0:nti[0]);
printf("%d\n", 1[nti]);
}
/************************/

Mark Bluemel

unread,
Apr 24, 2009, 9:55:14 AM4/24/09
to

Nice...

Mark Bluemel

unread,
Apr 24, 2009, 9:59:26 AM4/24/09
to

Fair comment. Could also be done as an exercise in recursive functions.

Depending on his tutor, he could get bonus points for finding a "better"
solution.

Mark Bluemel

unread,
Apr 24, 2009, 10:04:01 AM4/24/09
to
Carl wrote:
>
> The thought had just occurred to me that he probably needs to use a for
> loop in this assignment. Sorry about the confusion. Here is the new
> fragment:
>
> /************************/
> #include <stdio.h>
>
> int main(void)
> {
> unsigned char nti[2] = {(~0["\355"]^7)};
> for(*(nti+1)&=0;--(*nti);nti[1]+= (nti[0]&1)?0:nti[0]);
> printf("%d\n", 1[nti]);
> }
> /************************/

You, sir, have a sick mind :-)

Han from China

unread,
Apr 24, 2009, 10:10:12 AM4/24/09
to
Han from China wrote:
> Any further problems, just let me know.

comp.lang.c - C questions, problems, etc.
misc.education - education, learning theory, etc.
alt.philosophy.debate - ethics debates, etc.

Carl

unread,
Apr 24, 2009, 10:10:42 AM4/24/09
to

Kenny McCormack

unread,
Apr 24, 2009, 10:16:36 AM4/24/09
to
In article <gssfra$vav$1...@news.motzarella.org>,
Mark Bluemel <mark_b...@pobox.com> wrote:
...

>Hint: If it were all the even numbers from 2 to 10,000,000 you wouldn't
>even consider doing individual addition would you?

Of course, on modern hardware, this could easily be done in a loop, in
less than a second, so why worry?

P.S. I just did it in GAWK (no time to write the C program) and it took
about 9 seconds, still not too bad.

Kenny McCormack

unread,
Apr 24, 2009, 10:17:17 AM4/24/09
to
In article <7b41f8926c8e519f...@pseudo.borked.net>,

Han from China <autistic...@comp.lang.c> wrote:
>Han from China wrote:
>> Any further problems, just let me know.
>
>comp.lang.c - C questions, problems, etc.
>misc.education - education, learning theory, etc.
>alt.philosophy.debate - ethics debates, etc.

So simple when you lay it out like that, isn't it?

Still, some seem to be confused by the concepts...

Chris Dollin

unread,
Apr 24, 2009, 10:20:27 AM4/24/09
to
azo...@gmail.com wrote:

In the spirit of all the other pseudo-answers:

int main(void)
{ long sum = 0, even_number = 0
; while (even_number < 323081) sum += even_number, even_number += 2
; return 0
; }

--
"Don't pluck it as you pass." - Trees, /The Garden of Jane Delawney/

Hewlett-Packard Limited registered office: Cain Road, Bracknell,
registered no: 690597 England Berks RG12 1HN

nick_keigh...@hotmail.com

unread,
Apr 24, 2009, 10:36:39 AM4/24/09
to
On 24 Apr, 13:56, azo...@gmail.com wrote:

rather than give you the C here is a solution is "pseudo-code".
Simply translate into C

(define (sum-even n)
(if (zero? n)
0
(+ (if (even? n) n 0)
(sum-even (- n 1)))))

(sum-even 20)

dfighter

unread,
Apr 24, 2009, 10:47:55 AM4/24/09
to
Kenny, why would you bother to do something wrong when you know how to
do it right?
FYI more powerful HW doesn't mean that you can or need to write slow
code. It means that with the same fast code you can calculate even faster.

dfighter

Han from China

unread,
Apr 24, 2009, 11:03:37 AM4/24/09
to
Kenny McCormack wrote:
> Han from China wrote:
>> comp.lang.c - C questions, problems, etc.
>> misc.education - education, learning theory, etc.
>> alt.philosophy.debate - ethics debates, etc.
>
> So simple when you lay it out like that, isn't it?
>
> Still, some seem to be confused by the concepts...

<OT>
True. I have my own beliefs about education, the knowledge
economy, etc. In the past, there have been some very
interesting discussions on misc.education (or it might have
been some related newsgroup) about learning theory and
knowledge acquisition. I have my favorite authors in the
field.
</OT>

Richard

unread,
Apr 24, 2009, 12:39:20 PM4/24/09
to
nick_keigh...@hotmail.com writes:

What pretentious nonsense for "pseudo code". Makes hardly any sense to
me without real thought and scrutiny and I've been professionally
programming various languages for almost 30 years.


--
"Avoid hyperbole at all costs, its the most destructive argument on
the planet" - Mark McIntyre in comp.lang.c

Richard

unread,
Apr 24, 2009, 12:43:04 PM4/24/09
to
Mark Bluemel <mark_b...@pobox.com> writes:

It is. But what about

"return 2468101214161820;"

(in true c.l.c fashion),

Keith Thompson

unread,
Apr 24, 2009, 12:51:51 PM4/24/09
to

#include <stdio.h>

int (*p(int n))(void);

int main(void)
{
int s = 0;
int t = !++s;
int i;
for (i = 2; i < 13; i ++) {
if (p(i)) {
if (++t&1) {
s *= i;
}
}
}
printf("%d\n", s);
return 0;
}

int (*p(int n))(void)
{
int i;
for (i = 2; i < n; i ++) {
if (n % i) {
continue;
}
return +'/'/(+'/')+(-'/')/'/';
}
return main;
}

Generalizing this solution is left as an exercise.

--
Keith Thompson (The_Other_Keith) ks...@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"

Willem

unread,
Apr 24, 2009, 1:06:03 PM4/24/09
to
Richard wrote:
) It is. But what about
)
) "return 2468101214161820;"
)
) (in true c.l.c fashion),

You forgot the " % 123 " fudge factor:

return 2468101214161820 % 123;


SaSW, Willem
--
Disclaimer: I am in no way responsible for any of the statements
made in the above text. For all I know I might be
drugged or something..
No I'm not paranoid. You all think I'm paranoid, don't you !
#EOT

blargg

unread,
Apr 24, 2009, 2:13:31 PM4/24/09
to
azo...@gmail.com wrote:
> COULD YOU PLEASE SOLVE THE FOLLOWING QUESTION.
>
> WRITE A PROGRAM IN C THAT WILL CALCULATE THE SUM OF EVEN NUMBERS FROM
> 0 TO 20?

Sure, but where's the question? You forgot to ask something.

Richard

unread,
Apr 24, 2009, 2:41:17 PM4/24/09
to
blarg...@gishpuppy.com (blargg) writes:

No he didn't. The question was line #1 of the body. What is it with
people trying to put people down here? Has the IQ plummeted in people's
haste to be "reg-like"?

Kenneth Brody

unread,
Apr 24, 2009, 3:44:00 PM4/24/09
to
Richard wrote:
> blarg...@gishpuppy.com (blargg) writes:
>
>> azo...@gmail.com wrote:
>>> COULD YOU PLEASE SOLVE THE FOLLOWING QUESTION.
>>>
>>> WRITE A PROGRAM IN C THAT WILL CALCULATE THE SUM OF EVEN NUMBERS FROM
>>> 0 TO 20?
>> Sure, but where's the question? You forgot to ask something.
>
> No he didn't. The question was line #1 of the body. What is it with
> people trying to put people down here? Has the IQ plummeted in people's
> haste to be "reg-like"?

If line #1 is a question, why does it not end in a question mark?

Since the rest of the post is not a question, despite line #1 saying that a
question was to follow, why does that part end with a question mark?

Given that the OP was "do my homework for me, please", without even a simple
"please" (actually, it was "DO MY HOMEWORK FOR ME!"), why do you feel he
needs any respect from anyone here? Note another recent thread, "Working
with char", which was also an assignment question. Here, however, the OP
said "here is what I've done so far, can you please help me with it", and
real help was given.

Finally, if line #1 really was the question, then the answer is nothing more
than a simple "yes".

--
Kenneth Brody

Phil Carmody

unread,
Apr 24, 2009, 4:11:55 PM4/24/09
to
azo...@gmail.com writes:
> COULD YOU PLEASE SOLVE THE FOLLOWING QUESTION.
>
> WRITE A PROGRAM IN C THAT WILL CALCULATE THE SUM OF EVEN NUMBERS FROM
> 0 TO 20?

Untested, may not even compile, but if so, getting it to run
will be good exercise for you:

I've tried to make it as readable as possible, unlike what
you'll get from some of the downright rotters in this group,
and have even helpfully commented it.

-- 8< --
#include <stdio.h>

int main(void)
{
int i=0, s=0;
s+=i; i+=2; /* s is 0, i is 2 */
s+=i; i+=2; /* s is 2, i is 4 */
s+=i; i+=2; /* s is 6, i is 6 */
s+=i; i+=2; /* s is 12, i is 8 */
s+=i; i+=2; /* s is 20, i is 6 */
/* We've now summed the even numbers from 0 to twenty, so stop */


printf("%d\n", s);
return 0;
}

-- 8< --


Hope that helps. Good luck with your assignment - I suggest changing
the variable names so that your instructor doesn't find this post if
he goes searching.

Cheers,
Phil
--
Marijuana is indeed a dangerous drug.
It causes governments to wage war against their own people.
-- Dave Seaman (sci.math, 19 Mar 2009)

Kaz Kylheku

unread,
Apr 24, 2009, 4:12:08 PM4/24/09
to
On 2009-04-24, Richard <rgr...@gmail.com> wrote:
> nick_keigh...@hotmail.com writes:
>
>> On 24 Apr, 13:56, azo...@gmail.com wrote:
>>> COULD YOU PLEASE SOLVE THE FOLLOWING QUESTION.
>>>
>>> WRITE  A PROGRAM IN C THAT WILL CALCULATE THE SUM OF EVEN NUMBERS FROM
>>> 0 TO 20?
>>
>> rather than give you the C here is a solution is "pseudo-code".
>> Simply translate into C
>>
>> (define (sum-even n)
>> (if (zero? n)
>> 0
>> (+ (if (even? n) n 0)
>> (sum-even (- n 1)))))
>>
>> (sum-even 20)
>
> What pretentious nonsense for "pseudo code". Makes hardly any sense to
> me without real thought and scrutiny and I've been professionally

So you want sense without thought?

> programming various languages for almost 30 years.

And yet you can't grok a trivial little Scheme function which follows directly
from the mathematics of defining this function recursively. Oops!

Keith Thompson

unread,
Apr 24, 2009, 4:16:40 PM4/24/09
to
Kenneth Brody <kenb...@spamcop.net> writes:
> Richard wrote:
>> blarg...@gishpuppy.com (blargg) writes:
>>
>>> azo...@gmail.com wrote:
>>>> COULD YOU PLEASE SOLVE THE FOLLOWING QUESTION.
>>>>
>>>> WRITE A PROGRAM IN C THAT WILL CALCULATE THE SUM OF EVEN NUMBERS FROM
>>>> 0 TO 20?
>>> Sure, but where's the question? You forgot to ask something.
>>
>> No he didn't. The question was line #1 of the body. What is it with
>> people trying to put people down here? Has the IQ plummeted in people's
>> haste to be "reg-like"?
>
> If line #1 is a question, why does it not end in a question mark?
>
[...]

> Given that the OP was "do my homework for me, please", without even a
> simple "please" (actually, it was "DO MY HOMEWORK FOR ME!"),

[...]

Actually, there was a simple "please", or rather a simple "PLEASE".

Nevertheless, I agree that politeness in response to such a "request"
is not warranted. (Personally, I tend to think that even those who
gave an outline of a solution, even without providing any code, were
being more helpful than they should, but YMMV.)

With luck, what the OP will learn from this will be more valuable than
an actual solution would be.

Carl

unread,
Apr 24, 2009, 4:43:54 PM4/24/09
to
If his prof did see your post, he would still notice the same variables.
Also, it should be clear that this is a tutorial of a for loop. Why
don't you leave the unrolling to the compiler?

Kenny McCormack

unread,
Apr 24, 2009, 4:47:39 PM4/24/09
to
In article <gst14d$pmd$3...@news.motzarella.org>,

Richard <rgr...@gmail.com> wrote:
>blarg...@gishpuppy.com (blargg) writes:
>
>> azo...@gmail.com wrote:
>>> COULD YOU PLEASE SOLVE THE FOLLOWING QUESTION.
>>>
>>> WRITE A PROGRAM IN C THAT WILL CALCULATE THE SUM OF EVEN NUMBERS FROM
>>> 0 TO 20?
>>
>> Sure, but where's the question? You forgot to ask something.
>
>No he didn't. The question was line #1 of the body. What is it with
>people trying to put people down here? Has the IQ plummeted in people's
>haste to be "reg-like"?

I think you're either with them or you're against them (them = the regs).
And it is pretty clear what happens to people who make it known that
they are against them.

>"Avoid hyperbole at all costs, its the most destructive argument on
>the planet" - Mark McIntyre in comp.lang.c

I still love this quote. It is simply incredible to realize that it is
entirely genuine (no hyperbole added on your part) and posted with, as
far as anyone can tell, an entirely straight face (by Mr. McInTired).

Sjouke Burry

unread,
Apr 24, 2009, 4:47:54 PM4/24/09
to
azo...@gmail.com wrote:
> COULD YOU PLEASE SOLVE THE FOLLOWING QUESTION.
>
> WRITE A PROGRAM IN C THAT WILL CALCULATE THE SUM OF EVEN NUMBERS FROM
> 0 TO 20?
Whats the name and email address of your teacher?
We will mail the solution there.

Lew Pitcher

unread,
Apr 24, 2009, 5:00:08 PM4/24/09
to
On April 24, 2009 09:59, in comp.lang.c, Mark Bluemel
(mark_b...@pobox.com) wrote:

Yes. But if the OP can't solve the problem with a for() loop, then
he's /really/ in no shape to understand recursion ;-)

> Depending on his tutor, he could get bonus points for finding a "better"
> solution.

IIRC, there's a precedent for that.

--
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. ------


Kenneth Brody

unread,
Apr 24, 2009, 5:10:00 PM4/24/09
to
Keith Thompson wrote:
> Kenneth Brody <kenb...@spamcop.net> writes:
>> Richard wrote:
>>> blarg...@gishpuppy.com (blargg) writes:
>>>
>>>> azo...@gmail.com wrote:
>>>>> COULD YOU PLEASE SOLVE THE FOLLOWING QUESTION.
[...]
>> Given that the OP was "do my homework for me, please", without even a
>> simple "please" (actually, it was "DO MY HOMEWORK FOR ME!"),
> [...]
>
> Actually, there was a simple "please", or rather a simple "PLEASE".

Ah, so there is. I missed it in all the noise.

> Nevertheless, I agree that politeness in response to such a "request"
> is not warranted. (Personally, I tend to think that even those who
> gave an outline of a solution, even without providing any code, were
> being more helpful than they should, but YMMV.)

I was thinking that a simple printf("110\n") with appropriate function
wrappers and headers would have sufficed. Though I do see the problem was
stated to "calculate", not "display" the sum. Perhaps correcting that could
be left as an exercise to the reader?

> With luck, what the OP will learn from this will be more valuable than
> an actual solution would be.

Unfortunately, my experience on Usenet says it will probably be otherwise.

--
Kenneth Brody

osmium

unread,
Apr 24, 2009, 5:18:28 PM4/24/09
to
"Keith Thompson" wrote:

> With luck, what the OP will learn from this will be more valuable than
> an actual solution would be.

For a computer science course I have my doubts; if it happens to be in
abnormal psychology, I agree.


user923005

unread,
Apr 24, 2009, 5:42:19 PM4/24/09
to
On Apr 24, 12:44 pm, Kenneth Brody <kenbr...@spamcop.net> wrote:
> Richard wrote:

I swear, some people are *SO* unhelpful. Let's give the poor O.P. a
break.
Here is my {optimal} solution:

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

int main(void)
{
puts("THE SUM OF ALL EVEN NUMBERS FROM 2 TO 20 INCLUSIVE IS
110.");
return EXIT_SUCCESS;
}

;-)
I screamed, because he screamed. I figure he likes screaming.

Of course, there is the straight-forward method:

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

int main(void)
{
int i;
int sum = 0;
for (i = 1; i <= 20; i+=2)
sum += i;
printf("SUM ALSO EQUALS %.0f\n",
exp(log((double)(((20 * 20 + 20) / 2) - sum))));
return EXIT_SUCCESS;
}

Not only have we found an alternate way to calculate the sum
effectively, but we have also verified that math works (to the great
relief of mathematicians world-wide).

blargg

unread,
Apr 24, 2009, 5:53:02 PM4/24/09
to
Carl wrote:
> Phil Carmody wrote:
> > azo...@gmail.com writes:
> >> COULD YOU PLEASE SOLVE THE FOLLOWING QUESTION.
> >>
> >> WRITE A PROGRAM IN C THAT WILL CALCULATE THE SUM OF EVEN NUMBERS FROM
> >> 0 TO 20?
[...]

> > int main(void)
> > {
> > int i=0, s=0;
> > s+=i; i+=2; /* s is 0, i is 2 */
> > s+=i; i+=2; /* s is 2, i is 4 */
> > s+=i; i+=2; /* s is 6, i is 6 */
> > s+=i; i+=2; /* s is 12, i is 8 */
> > s+=i; i+=2; /* s is 20, i is 6 */
> > /* We've now summed the even numbers from 0 to twenty, so stop */
> > printf("%d\n", s);
> > return 0;
> > }
[...]

> Also, it should be clear that this is a tutorial of a for loop. Why
> don't you leave the unrolling to the compiler?

It should also be clear that this tutorial is assigned so that the student
in the class can learn from implementing it. Most of the responders have
respected this, and avoided posting the kind of solution appropriate, so
as to avoid robbing the student of the learning experience.

user923005

unread,
Apr 24, 2009, 6:18:15 PM4/24/09
to

It also isn't obvious that the instructor did want a for() loop. If
it were truly a requirement, the instructor would have stated it.

Probably, a while (cond) {} construct or do {} while (cond); construct
would have been just as nice. As someone who once taught the C
language in college, I can say that I very rarely told the students
exactly what construct to use, and in those few cases it was usually
to show contrasts like:

1. Perform the following task /* Task defined here */ with a for()
loop.
2. Perform the same task with a while (condition) {} loop.
3. Perform the same task with a do {} while (condition) loop.
4. Which way did you like better and why?

I have found that when you try to be restrictive, it limits the
creativity of the students, who will often find a better solution than
the one that you imagined.

I did have a few unreasonable restrictions (such as no use of goto in
the program whatsoever -- not even in a nested loop where an inner
break was needed). I found this condition necessary, because Olympic
College in Bremerton Washington is by a Navy base and more than half
of the students were in the Navy. Nothing wrong with that per se, but
a lot of them were Fortran and COBOL programmers from way, way back in
the day and they simply were in love with the goto.

Han from China

unread,
Apr 24, 2009, 6:27:31 PM4/24/09
to
By the way, Azo, the solution I gave you is a serious one. If you
have any more assignments to do, just let me know on this newsgroup,
and I'll help you as best I can. I consider opinions about learning
theory, plagiarism, ethics, etc., off-topic for this newsgroup, so
you can count on me to address the C content of your posts. Suffice
it to say, I have my own views about learning and education, views
I picked up from a number of 20th-century thinkers who were experts
in the field and whose opinions I respect. I'd suggest making sure
you understand the solutions I give you, and perhaps after reading
them, try your hand at coding the solutions without looking at mine.
All the best with your studies, buddy.

Mark McIntyre

unread,
Apr 24, 2009, 6:39:04 PM4/24/09
to
On 24/04/09 18:06, Willem wrote:
> Richard wrote:
> ) It is. But what about
> )
> ) "return 2468101214161820;"
> )
> ) (in true c.l.c fashion),
>
> You forgot the " % 123 " fudge factor:
>
> return 2468101214161820 % 123;

Even nicer...

user923005

unread,
Apr 24, 2009, 6:52:08 PM4/24/09
to
On Apr 24, 3:27 pm, Han from China <autistic-pedan...@comp.lang.c>
wrote:

Do you really imagine that doing someone's assignment for them is a
benefit?

I literally cannot imagine anything more damaging. You are robbing
that student of his/her education. The teacher already knows the
answer to the question and they simply want the student to reason
through the process and find out what bits are hard and what bits are
easy. It is likely that the student does not know how to complete the
task. But if you simply perform the task for them, they are no better
off than before they started.

Besides the fact that they are avoiding the learning of the necessary
skill (seeing someone else do it does not teach the skill) they are
also doing something that is dishonest and will get them expelled from
most universities if caught. It is not improbable that becoming a
liar and a cheat may carry on forward in life as well if they practice
at it and are encouraged to do it.

Consider also the money that either they or their parents are spending
on an education that is simply being flushed down the toilet. When
you act in an unhelpful manner it is really robbing *someone* of money
that they are spending to learn.

I think you are defining yourself in a bad way (being a whinging twit
at times pales in comparison -- because we are all whinging twits from
time to time -- just some more than others). But perhaps only to some
people. Others may consider you a hero, though their opinion may
change down the road.

IMO-YMMV

blargg

unread,
Apr 24, 2009, 7:43:39 PM4/24/09
to
user923005 wrote:
> On Apr 24, 3:27=A0pm, Han from China <autistic-pedan...@comp.lang.c>

> wrote:
> > By the way, Azo, the solution I gave you is a serious one. If you
> > have any more assignments to do, just let me know on this newsgroup,
> > and I'll help you as best I can. I consider opinions about learning
> > theory, plagiarism, ethics, etc., off-topic for this newsgroup, so
> > you can count on me to address the C content of your posts. Suffice
> > it to say, I have my own views about learning and education, views
> > I picked up from a number of 20th-century thinkers who were experts
> > in the field and whose opinions I respect. I'd suggest making sure
> > you understand the solutions I give you, and perhaps after reading
> > them, try your hand at coding the solutions without looking at mine.
> > All the best with your studies, buddy.
>
> Do you really imagine that doing someone's assignment for them is a
> benefit?

Are you surprised that someone can come up with a different view than you
have, or do you assume that any differing views must not have been as
well-thought as yours? In matters like this, it's always an issue of what
the long-term effect is, which is hard to predict. Now if you were going
by actual data on the long-term effect this has had in specific cases,
it'd be hard to argue against.

> I literally cannot imagine anything more damaging. You are robbing
> that student of his/her education.

Nobody forced the student to post here. He most likely went somewhere else
and found the answer anyway.

> The teacher already knows the
> answer to the question and they simply want the student to reason
> through the process and find out what bits are hard and what bits are
> easy. It is likely that the student does not know how to complete the
> task. But if you simply perform the task for them, they are no better
> off than before they started.

Depends on the student's goal.

[...]


> Consider also the money that either they or their parents are spending
> on an education that is simply being flushed down the toilet. When
> you act in an unhelpful manner it is really robbing *someone* of money
> that they are spending to learn.

[...]

Who again is wasting the money? Not the student, but people on a Usenet
newsgroup? Come on! The main reason I give sarcastic replies to such posts
is that I find them somewhat rude, and don't think very highly of people
wasting the group's time with requests for spoon-feeding. The best
exchanges with students here are those where the student tells us his
goal, how he is currently trying (but failing) to achieve it, and then
pays attention to replies and gives feedback as to what insights that
gives him. These exchanges are then of value to other readers facing
similar problems, or who simply enjoy reading such fruitful exchanges.

pete

unread,
Apr 24, 2009, 7:54:26 PM4/24/09
to
azo...@gmail.com wrote:
> COULD YOU PLEASE SOLVE THE FOLLOWING QUESTION.
>
> WRITE A PROGRAM IN C THAT WILL CALCULATE THE SUM OF EVEN NUMBERS FROM
> 0 TO 20?

/* BEGIN new.c */

#include <stdio.h>

#define INTEGER 20

int main(void)
{
long unsigned integer = INTEGER;
long unsigned original = INTEGER;

integer -= integer & 1;
printf("The sum of all even integers from 0 to %lu, is %lu.\n",
original, integer * integer / 4 + integer / 2);

return 0;
}

/* END new.c */


--
pete

user923005

unread,
Apr 24, 2009, 8:31:59 PM4/24/09
to
On Apr 24, 4:43 pm, blargg....@gishpuppy.com (blargg) wrote:
> user923005 wrote:
> > On Apr 24, 3:27=A0pm, Han from China <autistic-pedan...@comp.lang.c>
> > wrote:
> > > By the way, Azo, the solution I gave you is a serious one. If you
> > > have any more assignments to do, just let me know on this newsgroup,
> > > and I'll help you as best I can. I consider opinions about learning
> > > theory, plagiarism, ethics, etc., off-topic for this newsgroup, so
> > > you can count on me to address the C content of your posts. Suffice
> > > it to say, I have my own views about learning and education, views
> > > I picked up from a number of 20th-century thinkers who were experts
> > > in the field and whose opinions I respect. I'd suggest making sure
> > > you understand the solutions I give you, and perhaps after reading
> > > them, try your hand at coding the solutions without looking at mine.
> > > All the best with your studies, buddy.
>
> > Do you really imagine that doing someone's assignment for them is a
> > benefit?
>
> Are you surprised that someone can come up with a different view than you
> have, or do you assume that any differing views must not have been as
> well-thought as yours? In matters like this, it's always an issue of what
> the long-term effect is, which is hard to predict. Now if you were going
> by actual data on the long-term effect this has had in specific cases,
> it'd be hard to argue against.

And yet people would argue anyway. It would seem fairly obvious that
student exercises are meant to be worked out by the students and also
that there is value in student exercises. But it is certainly
possible that the entire world's educational system is done completely
wrong and that the right way to solve problems is to cheat and avoid
practice. Somehow I doubt that this will work well in the long run
because I personally know people who have tried this method and it did
not work out well for them. Of course, a few experiences and what I
consider common sense do not amount to a clinical and scientific
study. I will leave that to someone else to conduct.

> > I literally cannot imagine anything more damaging.  You are robbing
> > that student of his/her education.
>
> Nobody forced the student to post here. He most likely went somewhere else
> and found the answer anyway.

I see no fault in the student posting here. I see no harm, either, in
redirection answers, hints as to a procedure, gag answers and the
like. I do see harm in giving the student the answer such that they
are not required to think on their own or try things by themselves.

If the student were to have posted differently (e.g. after describing
the assignment asked something like 'Where do I start?') I suspect
that they would have gotten better help. When problems are posed in a
way that *looks* like an attempt to avoid learning, the answers given
are often dripping with derision. Probably, it would have been a lot
better if everyone had assumed that the student was simply making an
honest appeal for help and not looking for cheating assistance.

> > The teacher already knows the
> > answer to the question and they simply want the student to reason
> > through the process and find out what bits are hard and what bits are
> > easy.  It is likely that the student does not know how to complete the
> > task.  But if you simply perform the task for them, they are no better
> > off than before they started.
>
> Depends on the student's goal.

If cheating is the answer, then the goal is a bad one.

> [...]> Consider also the money that either they or their parents are spending
> > on an education that is simply being flushed down the toilet.  When
> > you act in an unhelpful manner it is really robbing *someone* of money
> > that they are spending to learn.
>
> [...]
>
> Who again is wasting the money? Not the student, but people on a Usenet
> newsgroup?

Do you know what tuition costs at even a public university? Add in
books, room and board and we are talking serious money. The loss does
not stop there. This person may eventually come to work for you (or
may even become your boss). This will cost *you* money eventually if
they have avoided learning.

> Come on! The main reason I give sarcastic replies to such posts
> is that I find them somewhat rude, and don't think very highly of people
> wasting the group's time with requests for spoon-feeding.

I have no problem with requests for spoon feeding. At some point
everyone is a complete neophyte at everything. We add skills over
time. Asking questions is a good way to learn, and neophyte questions
are what we get out of neophytes. To expect otherwise is not
realistic. It's not absurd to imagine that the O.P. was simply
frustrated at not knowing where to start. If the question had been
phrased better {IOW it does not look like a rephrasal of "please help
me cheat"}, I suspect that the student would receive genuine help.
When it comes to homework assignments, I think that we can see some
excellent guidelines here:
http://home.att.net/~jackklein/ctips01.html
If students were to follow these guidelines, then I suspect that
everyone would benefit. Students will not always follow those
guidelines, and so they are going to get a mix of good answers, bad
answers, gag answers and etc.

> The best
> exchanges with students here are those where the student tells us his
> goal, how he is currently trying (but failing) to achieve it, and then
> pays attention to replies and gives feedback as to what insights that
> gives him.

I agree.

> These exchanges are then of value to other readers facing
> similar problems, or who simply enjoy reading such fruitful exchanges.

This is also true. Certainly, well phrased questions that demonstrate
willingness to learn on the part of the student will gather the best
responses.

CBFalconer

unread,
Apr 24, 2009, 8:29:22 PM4/24/09
to
azo...@gmail.com wrote:
>
> COULD YOU PLEASE SOLVE THE FOLLOWING QUESTION.
>
> WRITE A PROGRAM IN C THAT WILL CALCULATE THE SUM OF EVEN NUMBERS
> FROM 0 TO 20?

#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.

--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home.att.net>
Try the download section.

Richard Heathfield

unread,
Apr 24, 2009, 8:41:57 PM4/24/09
to
user923005 said:

<snip>



> Do you really imagine that doing someone's assignment for them is
> a benefit?
>
> I literally cannot imagine anything more damaging. You are
> robbing that student of his/her education.

I don't see the problem.

If somebody here wishes to take on another person's workload, that's
their business. If they wish that person to become dependent on
them, that's their business. If they wish that person to be
hassling them every five minutes with requests for modifications,
that's their business. And if they take on, say, a dozen such OPs,
I doubt very much whether they'll have any more time for posting
anything to Usenet other than their spoonfeeding articles.

So I don't see the problem - there doesn't seem to be a downside.

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999

Lew Pitcher

unread,
Apr 24, 2009, 8:57:28 PM4/24/09
to
On April 24, 2009 20:29, in comp.lang.c, CBFalconer (cbfal...@yahoo.com)
wrote:

> azo...@gmail.com wrote:
>>
>> COULD YOU PLEASE SOLVE THE FOLLOWING QUESTION.
>>
>> WRITE A PROGRAM IN C THAT WILL CALCULATE THE SUM OF EVEN NUMBERS
>> FROM 0 TO 20?
>
> #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;
> }

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

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;

Richard Tobin

unread,
Apr 24, 2009, 9:06:53 PM4/24/09
to
In article <b1b06a9a-adf0-4e0f...@f19g2000yqh.googlegroups.com>,

<azo...@gmail.com> wrote:
>COULD YOU PLEASE SOLVE THE FOLLOWING QUESTION.
>
>WRITE A PROGRAM IN C THAT WILL CALCULATE THE SUM OF EVEN NUMBERS FROM
>0 TO 20?

#include <stdio.h>

int total(int n)
{
return n < 0 ? 0 : n + total(n-2);
}

int main(void)
{
printf("%d\n", total(20));

return 0;
}

Unfortunately this program does not conform to the C standard.

-- Richard
--
Please remember to mention me / in tapes you leave behind.

Richard Tobin

unread,
Apr 24, 2009, 9:08:28 PM4/24/09
to
In article <49F25962...@yahoo.com>,

CBFalconer <cbfal...@maineline.net> wrote:
>but you can't enter that in your machine with your broken shift
>key.

Use the DS9000's case stropping mode.

user923005

unread,
Apr 24, 2009, 9:05:57 PM4/24/09
to
On Apr 24, 5:41 pm, Richard Heathfield <r...@see.sig.invalid> wrote:
> user923005 said:
>
> <snip>
>
> > Do you really imagine that doing someone's assignment for them is
> > a benefit?
>
> > I literally cannot imagine anything more damaging.  You are
> > robbing that student of his/her education.
>
> I don't see the problem.
>
> If somebody here wishes to take on another person's workload, that's
> their business. If they wish that person to become dependent on
> them, that's their business. If they wish that person to be
> hassling them every five minutes with requests for modifications,
> that's their business. And if they take on, say, a dozen such OPs,
> I doubt very much whether they'll have any more time for posting
> anything to Usenet other than their spoonfeeding articles.
>
> So I don't see the problem - there doesn't seem to be a downside.

5 years from now the person who failed to learn gets hired by your
company or even becomes your boss.
Can you see a downside now? (Dilbert comics spring to mind -- they
are not always completely removed from reality).

Imagine that this person goes to work somewhere else. Their
productivity is low. This lowers the productivity of the company that
they work for. Now, one person with low productivity will have little
impact on an economy. But millions of them will.

I do realize that your response is very much tongue-in-cheek. I think
it is also possible that the O.P. was not simply hoping to cheat.
They may have really wanted *actual* help, but simply phrased the
question in the worst possible manner. It may even be a complete
troll. We'll probably never find out. But I do recall (in the past)
where students have -- with a bit of prodding -- made substantial
progress even after starting off on the wrong foot.

Let's be honest also -- we have *all* done something lazy some time in
our lives. It would have been better to think things out carefully or
to put more effort into a problem that we faced. And we made a bad
choice (the lazy choice is almost always a bad one). If those choices
received plenty of encouragement, we could possibly have received some
damage from it.

In most places you have to be pretty smart even to get into college.
So the capabiltiy to solve these sorts of problems is probably
present, somewhere lurking under the skin. If we can coax out that
ability out of those asking the simple questions then they will have
learned. I am one of those people who see something noble in
teaching. In fact, when I retire from "actual work" I want to teach a
class at a junior college, just because it's such a wonderful and fun
thing to do.

In addition, I suspect that the hapless harmers are not detained from
making annoying posts any more than if they were doing some other kind
of harmful posting. Bad posting comes from bad posters. In general
the only real harm is to neophytes anyway, since they are the ones
that do not understand why the posts are either wrong or harmful.

IMO-YMMV

user923005

unread,
Apr 24, 2009, 9:11:48 PM4/24/09
to
On Apr 24, 6:06 pm, rich...@cogsci.ed.ac.uk (Richard Tobin) wrote:
> In article <b1b06a9a-adf0-4e0f-9a99-d06e7ba89...@f19g2000yqh.googlegroups.com>,

>
>  <azo...@gmail.com> wrote:
> >COULD YOU PLEASE SOLVE THE FOLLOWING QUESTION.
>
> >WRITE  A PROGRAM IN C THAT WILL CALCULATE THE SUM OF EVEN NUMBERS FROM
> >0 TO 20?
>
> #include <stdio.h>
>
> int total(int n)
> {
>     return n < 0 ? 0 : n + total(n-2);
>
> }
>
> int main(void)
> {
>     printf("%d\n", total(20));
>
>     return 0;
>
> }
>
> Unfortunately this program does not conform to the C standard.

OK. I puzzled and puzzled and I still don't see anything wrong with
it.
In what way is the program non-conforming?

user923005

unread,
Apr 24, 2009, 9:15:52 PM4/24/09
to
On Apr 24, 5:57 pm, Lew Pitcher <lpitc...@teksavvy.com> wrote:
> On April 24, 2009 20:29, in comp.lang.c, CBFalconer (cbfalco...@yahoo.com)

> wrote:
>
>
>
>
>
> > azo...@gmail.com wrote:
>
> >> COULD YOU PLEASE SOLVE THE FOLLOWING QUESTION.
>
> >> WRITE  A PROGRAM IN C THAT WILL CALCULATE THE SUM OF EVEN NUMBERS
> >> FROM 0 TO 20?
>
> > #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;
> > }
>
> First observation: this only counts even integers that range from 0 to 19.
> Was this intentional?

Peter Seebach had a knack to throw in mistakes that were *really*
funny (the tone of which can easily be found in the IAQ[1]). I sure
miss his posts.

> 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;
>   }
>

Yes, but where's the joke?
When it comes to a bare request for homework answers, I see the
following sensible replies:
1. Flames
2. Gag answers
3. Requests for clarification
4. Nudges in the right direction.

and the following insensible replies:
1. Correct and accurate completed assignements.

IMO-YMMV


[1] http://www.seebs.net/faqs/c-iaq.html

Richard Heathfield

unread,
Apr 24, 2009, 9:22:21 PM4/24/09
to
Richard Tobin said:

> In article
>
<b1b06a9a-adf0-4e0f...@f19g2000yqh.googlegroups.com>,
> <azo...@gmail.com> wrote:
>>COULD YOU PLEASE SOLVE THE FOLLOWING QUESTION.
>>
>>WRITE A PROGRAM IN C THAT WILL CALCULATE THE SUM OF EVEN NUMBERS
>>FROM 0 TO 20?
>
> #include <stdio.h>
>
> int total(int n)
> {
> return n < 0 ? 0 : n + total(n-2);
> }
>
> int main(void)
> {
> printf("%d\n", total(20));
>
> return 0;
> }
>
> Unfortunately this program does not conform to the C standard.

Um, why not? Looks fine to me.

Richard Heathfield

unread,
Apr 24, 2009, 9:34:30 PM4/24/09
to
user923005 said:

> On Apr 24, 5:41 pm, Richard Heathfield <r...@see.sig.invalid>
> wrote:
>> user923005 said:
>>
>> <snip>
>>
>> > Do you really imagine that doing someone's assignment for them
>> > is a benefit?
>>
>> > I literally cannot imagine anything more damaging. You are
>> > robbing that student of his/her education.
>>
>> I don't see the problem.
>>
>> If somebody here wishes to take on another person's workload,
>> that's their business. If they wish that person to become
>> dependent on them, that's their business. If they wish that
>> person to be hassling them every five minutes with requests for
>> modifications, that's their business. And if they take on, say, a
>> dozen such OPs, I doubt very much whether they'll have any more
>> time for posting anything to Usenet other than their spoonfeeding
>> articles.
>>
>> So I don't see the problem - there doesn't seem to be a downside.
>
> 5 years from now the person who failed to learn gets hired by your
> company or even becomes your boss.
> Can you see a downside now?

No. If he becomes a co-worker, I can get him re-trained, re-deployed
(a tactic I have employed on occasion) or, in extreme cases, fired
(a tactic I have only employed on *one* occasion where eight people
took six months to write a 450-line program that only worked by the
grace of $deity: char *x = (char *)malloc(sizeof(char)); strcpy(x,
"ABC"); and so on).

If he becomes my boss, I can simply take a judgement on whether he
is a good boss (i.e. will either do The Right Thing unprovoked, or
can be steered into doing The Right Thing). If he isn't, I can go
elsewhere. I don't have a problem with that.

> (Dilbert comics spring to mind --
> they are not always completely removed from reality).

Actually, Scott Adams has to reach further and further into
hyperbole in a desperate attempt to match reality! Nevertheless,
reasonable people are not, strictly speaking, forbidden from
becoming managers. Nor are employees quite as chained down as
Dilbert seems to believe.

> Imagine that this person goes to work somewhere else. Their
> productivity is low. This lowers the productivity of the company
> that they work for. Now, one person with low productivity will
> have little impact on an economy. But millions of them will.

Economic Darwinism will remove such companies (those who hire lazy
people) from the "gene" pool.

Bottom line - there will always be some people in this group who are
prepared to spoonfeed the lazy. As far as I'm concerned, that's
their problem, not mine.

Han from China

unread,
Apr 24, 2009, 10:02:54 PM4/24/09
to
user923005 wrote:
> When it comes to a bare request for homework answers, I see the
> following sensible replies:
> 1. Flames
> 2. Gag answers
> 3. Requests for clarification
> 4. Nudges in the right direction.
>
> and the following insensible replies:
> 1. Correct and accurate completed assignements.
>
> IMO-YMMV

<OT>
Dan, I've read all your posts in this thread, and I understand your
view and respect your right to hold it. I used to have a similar
view, but then I became largely disillusioned with traditional
education. Moreover, every new poster here has a back story about
which we can make only guesses. There are an incalculable number
of variables at play, and there's no way to predict whether the
causal chain that's set into motion by supplying the OP with an
answer will lead to good or evil. I find it prudent to restrict
myself to answering posters' C questions and not bothering with
the unknowns.
</OT>

Kenny McCormack

unread,
Apr 24, 2009, 10:15:14 PM4/24/09
to
In article <65c4268c3504fd42...@pseudo.borked.net>,
Han from China <autistic...@comp.lang.c> wrote:
...

>Dan, I've read all your posts in this thread, and I understand your
>view and respect your right to hold it. I used to have a similar
>view, but then I became largely disillusioned with traditional
>education. Moreover, every new poster here has a back story about
>which we can make only guesses. There are an incalculable number
>of variables at play, and there's no way to predict whether the
>causal chain that's set into motion by supplying the OP with an
>answer will lead to good or evil. I find it prudent to restrict
>myself to answering posters' C questions and not bothering with
>the unknowns.

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).
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...
3) Said person looks for help on CLC and gets the usual
treatment, and subsequently kills himself.

You want that on your conscience?

osmium

unread,
Apr 24, 2009, 11:18:49 PM4/24/09
to
"CBFalconer" wrote:

>> COULD YOU PLEASE SOLVE THE FOLLOWING QUESTION.
>>
>> WRITE A PROGRAM IN C THAT WILL CALCULATE THE SUM OF EVEN NUMBERS
>> FROM 0 TO 20?
>
> #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.


Han from China

unread,
Apr 25, 2009, 12:40:23 AM4/25/09
to
Kenny McCormack wrote:
> 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).
> 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...
> 3) Said person looks for help on CLC and gets the usual
> treatment, and subsequently kills himself.
>
> You want that on your conscience?

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.

Richard

unread,
Apr 25, 2009, 12:48:17 AM4/25/09
to
gaz...@shell.xmission.com (Kenny McCormack) writes:

> In article <gst14d$pmd$3...@news.motzarella.org>,


> Richard <rgr...@gmail.com> wrote:
>>blarg...@gishpuppy.com (blargg) writes:
>>

>>> azo...@gmail.com wrote:
>>>> COULD YOU PLEASE SOLVE THE FOLLOWING QUESTION.
>>>>
>>>> WRITE A PROGRAM IN C THAT WILL CALCULATE THE SUM OF EVEN NUMBERS FROM
>>>> 0 TO 20?
>>>

>>> Sure, but where's the question? You forgot to ask something.
>>
>>No he didn't. The question was line #1 of the body. What is it with
>>people trying to put people down here? Has the IQ plummeted in people's
>>haste to be "reg-like"?
>

> I think you're either with them or you're against them (them = the regs).
> And it is pretty clear what happens to people who make it known that
> they are against them.
>
>>"Avoid hyperbole at all costs, its the most destructive argument on
>>the planet" - Mark McIntyre in comp.lang.c
>
> I still love this quote. It is simply incredible to realize that it is
> entirely genuine (no hyperbole added on your part) and posted with, as
> far as anyone can tell, an entirely straight face (by Mr. McInTired).
>

I actually killed that thread and have no idea, to this day, if he's an
awful lot cleverer than his cocksure and arrogant posts indicate. I
almost *want* to think he was trolling. Alas, (indeed, quite and
almost), I suspect not.


--
"Avoid hyperbole at all costs, its the most destructive argument on
the planet" - Mark McIntyre in comp.lang.c

Richard

unread,
Apr 25, 2009, 12:49:36 AM4/25/09
to
user923005 <dco...@connx.com> writes:

> On Apr 24, 3:27 pm, Han from China <autistic-pedan...@comp.lang.c>
> wrote:
>> By the way, Azo, the solution I gave you is a serious one. If you
>> have any more assignments to do, just let me know on this newsgroup,
>> and I'll help you as best I can. I consider opinions about learning
>> theory, plagiarism, ethics, etc., off-topic for this newsgroup, so
>> you can count on me to address the C content of your posts. Suffice
>> it to say, I have my own views about learning and education, views
>> I picked up from a number of 20th-century thinkers who were experts
>> in the field and whose opinions I respect. I'd suggest making sure
>> you understand the solutions I give you, and perhaps after reading
>> them, try your hand at coding the solutions without looking at mine.
>> All the best with your studies, buddy.
>
> Do you really imagine that doing someone's assignment for them is a
> benefit?

Did you hear about Google?

Lots of answers. Lots of half assed attempts. Better he gets the right
one hear and can then ask questions.

Hint : it's not what you know, it's about if you know how to be sure you
got the right answer.

Richard

unread,
Apr 25, 2009, 12:50:49 AM4/25/09
to
CBFalconer <cbfal...@yahoo.com> writes:

> azo...@gmail.com wrote:
>>
>> COULD YOU PLEASE SOLVE THE FOLLOWING QUESTION.
>>
>> WRITE A PROGRAM IN C THAT WILL CALCULATE THE SUM OF EVEN NUMBERS
>> FROM 0 TO 20?
>
> #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.

His keyboard settings are out of the ISO C standard.

Harald van Dijk

unread,
Apr 25, 2009, 3:23:22 AM4/25/09
to
Richard Heathfield wrote:
> Richard Tobin said:
>> In article
>> #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.

Mark McIntyre

unread,
Apr 25, 2009, 5:23:51 AM4/25/09
to
On 25/04/09 00:43, blargg wrote:
> user923005 wrote:

>> Do you really imagine that doing someone's assignment for them is a
>> benefit?
>
> Are you surprised that someone can come up with a different view than you

> have,or do you assume that any differing views must not have been as
> well-thought as yours?

Personally, neither. However it seems likely to me that Han's comment
was purposefully intended to enrage regs rather than being a real
opinion. He knows how cheating is regarded here.

In matters like this, it's always an issue of what
> the long-term effect is, which is hard to predict.

Not really - about 10000 years of study have gone into determining that
people learn best if they do their own homework.

> Now if you were going
> by actual data on the long-term effect this has had in specific cases,
> it'd be hard to argue against.

See any educational programme, ever. Even the current UK ones.

> Who again is wasting the money? Not the student,

Yes. His, or whoever is paying for him to get an education.

Just for the record, I have fired people whom I was tricked into
employing due to them copying someone else's work and presenting it as
their own. I've had interview candidates turn up with great scores on
the pre-interview test who were completely unable to explain their code.
When I was teaching and marking exams, I would see the copy/paste
answers, often because the same copies have been going around since the
year dot with the same errors and typos, and papers got marked down
appropriately. Education is about /learning/ not about photocopying.

--
Mark McIntyre

CLC FAQ <http://c-faq.com/>
CLC readme: <http://www.ungerhu.com/jxh/clc.welcome.txt>

Richard Heathfield

unread,
Apr 25, 2009, 6:07:10 AM4/25/09
to
Harald van D?k said:

Oh, yes. Easily missed.

user923005

unread,
Apr 25, 2009, 7:44:17 AM4/25/09
to
On Apr 24, 9:40 pm, Han from China <autistic-pedan...@comp.lang.c>
wrote:

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.

Kenny McCormack

unread,
Apr 25, 2009, 8:33:50 AM4/25/09
to
In article <bf2c85f6-a9c1-4d30...@z8g2000prd.googlegroups.com>,
user923005 <dco...@connx.com> 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.

osmium

unread,
Apr 25, 2009, 9:28:04 AM4/25/09
to
"Harald van D?k" wrote:

> 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".


Han from China

unread,
Apr 25, 2009, 11:04:40 AM4/25/09
to
osmium wrote:
> Is there a way to know this kind of esoterica without studying the standard?
> Ideally a list of "gotchas".

No. Invariably when someone tries to offer a comprehensive list of
reserved identifiers, future directions, etc., it comes out wrong.

You have to keep in mind other esoterica, such as C90's gotcha about
6 significant characters and case insensitivity for certain identifiers.

What makes the standard particularly hard to read when it comes to
these gotchas is the indirect way of mentioning the members of the
set in question. To use an analogy, it's as if you have a basket
containing an apple, a carrot, and a banana -- and rather than
saying "I'm thinking of the apple", you say "I'm not thinking
of something that doesn't have seeds, and I'm not thinking of
something yellow or orange, and what I'm thinking of is excluded
from the set of purple monsters". So be prepared to draw up your
Venn diagrams when dissecting the standard.

Han from China

unread,
Apr 25, 2009, 11:09:43 AM4/25/09
to
user923005 wrote:
> 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.

A man needs help with C, and I have the answer. Should I help
him? It might be a habitual cheat or someone worse than a habitual
cheat. So don't help him.

> Even though the probability that it is the most beneficial thing is
> very near to zero.

This is all speculation. There is no quantitative way to demonstrate
that. And there is no crystal ball.

This newsgroup is about the C programming language. The OP asked
a C question, so it's not unreasonable that some people here may
be happy to answer the C question. misc.education and
alt.philosophy.debate would be the appropriate places for this other
kind of off-topic discussion, in my opinion.

Some people on this newsgroup (and I'm not talking about you) try
to impose a universal value system on all posters. This system covers
everything from Netiquette to topicality. This system is rife with
hypocrisy, and anyone who points out the hypocrisy gets ignored or
relegated to the troll bin (see the most recent example having to
do with long signatures, where I was completely ignored -- where
were you "fair and reasonable" folks then?). So pardon me if I'm
more than a bit incredulous about anything on this newsgroup that
carries undertones of a "community" value system.

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

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.

Lew Pitcher

unread,
Apr 25, 2009, 11:19:58 AM4/25/09
to
On April 24, 2009 22:15, in comp.lang.c, Kenny McCormack
(gaz...@shell.xmission.com) wrote:

> In article <65c4268c3504fd42...@pseudo.borked.net>,
> Han from China <autistic...@comp.lang.c> wrote:
> ...
>>Dan, I've read all your posts in this thread, and I understand your
>>view and respect your right to hold it. I used to have a similar
>>view, but then I became largely disillusioned with traditional
>>education. Moreover, every new poster here has a back story about
>>which we can make only guesses. There are an incalculable number
>>of variables at play, and there's no way to predict whether the
>>causal chain that's set into motion by supplying the OP with an
>>answer will lead to good or evil. I find it prudent to restrict
>>myself to answering posters' C questions and not bothering with
>>the unknowns.
>
> 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

Richard

unread,
Apr 25, 2009, 11:28:21 AM4/25/09
to
Han from China <autistic...@comp.lang.c> writes:

> user923005 wrote:
>> 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.
>
> A man needs help with C, and I have the answer. Should I help
> him? It might be a habitual cheat or someone worse than a habitual
> cheat. So don't help him.
>
>> Even though the probability that it is the most beneficial thing is
>> very near to zero.
>
> This is all speculation. There is no quantitative way to demonstrate
> that. And there is no crystal ball.
>
> This newsgroup is about the C programming language. The OP asked
> a C question, so it's not unreasonable that some people here may
> be happy to answer the C question. misc.education and
> alt.philosophy.debate would be the appropriate places for this other
> kind of off-topic discussion, in my opinion.

Exactly. How is Chuck not to know that main function he's whining about
(you know, int v void etc) is not ALSO a homework question.

>
> Some people on this newsgroup (and I'm not talking about you) try
> to impose a universal value system on all posters. This system covers
> everything from Netiquette to topicality. This system is rife with
> hypocrisy, and anyone who points out the hypocrisy gets ignored or
> relegated to the troll bin (see the most recent example having to
> do with long signatures, where I was completely ignored -- where
> were you "fair and reasonable" folks then?). So pardon me if I'm
> more than a bit incredulous about anything on this newsgroup that
> carries undertones of a "community" value system.
>
>> When something bad happens, the bad thing can teach us a lesson the
>> same way as when a good thing happens.
>
> 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.
>
>
> Yours,
> Han from China

--

Richard Heathfield

unread,
Apr 25, 2009, 11:35:31 AM4/25/09
to
user923005 said:

<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.

Dann, is there any point in this discussion? The correctness of your
position is so blindingly obvious that anyone who is amenable to
being persuaded was already persuaded long ago.

Han from China

unread,
Apr 25, 2009, 11:50:45 AM4/25/09
to
Richard wrote:
> Exactly. How is Chuck not to know that main function he's whining about
> (you know, int v void etc) is not ALSO a homework question.

Good point. Indeed, the only reason we know that this particular
case was a homework question is that the OP was honest enough
to say so.

Yours,
Han from China

--

blargg

unread,
Apr 25, 2009, 12:03:00 PM4/25/09
to
Han from China wrote:
> osmium wrote:
> > Is there a way to know this kind of esoterica without studying the
standard?
> > Ideally a list of "gotchas".
>
> No. Invariably when someone tries to offer a comprehensive list of
> reserved identifiers, future directions, etc., it comes out wrong.
[...]

> What makes the standard particularly hard to read when it comes to
> these gotchas is the indirect way of mentioning the members of the
> set in question. To use an analogy, it's as if you have a basket
> containing an apple, a carrot, and a banana -- and rather than
> saying "I'm thinking of the apple", you say "I'm not thinking
> of something that doesn't have seeds, and I'm not thinking of
> something yellow or orange, and what I'm thinking of is excluded
> from the set of purple monsters". So be prepared to draw up your
> Venn diagrams when dissecting the standard.

Heh, that captures the appearance well, though of course it's not
intentionally like that. I think the purpose is to avoid specifying the
same things more than once in the standard, reducing the chance of
inconsistency. The reserved names would mostly be embedded in the library
documentation. On the other hand, if the documentation is written in a
structured format that allows automated tools to produce derivitives,
having a known-correct list in the standard would be possible.

blargg

unread,
Apr 25, 2009, 12:10:11 PM4/25/09
to
user923005 wrote:
> Han from China wrote:
[...]

>> 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.
[...]

Oh well, the thread had to come to an end at some point (see Godwin).

Joe Wright

unread,
Apr 25, 2009, 1:08:18 PM4/25/09
to
Kenny McCormack wrote:
> In article <gssfra$vav$1...@news.motzarella.org>,
> Mark Bluemel <mark_b...@pobox.com> wrote:
> ...
>> Hint: If it were all the even numbers from 2 to 10,000,000 you wouldn't
>> even consider doing individual addition would you?
>
> Of course, on modern hardware, this could easily be done in a loop, in
> less than a second, so why worry?
>
> P.S. I just did it in GAWK (no time to write the C program) and it took
> about 9 seconds, still not too bad.
>
sum is 25000005000000 in 0 seconds.

--
Joe Wright
"Memory is the second thing to go. I forget what the first is."

Joe Wright

unread,
Apr 25, 2009, 1:10:10 PM4/25/09
to
Dik T. Winter wrote:

> In article <b1b06a9a-adf0-4e0f...@f19g2000yqh.googlegroups.com> azo...@gmail.com writes:
> > COULD YOU PLEASE SOLVE THE FOLLOWING QUESTION.
> >
> > WRITE A PROGRAM IN C THAT WILL CALCULATE THE SUM OF EVEN NUMBERS FROM
> > 0 TO 20?
>
> int main(void) {
> int sum;
>
> sum = 0+2+4+6+8+10+12+14+16+18+20;
> }
Is that what you call 'un-rolling'? :-)

Keith Thompson

unread,
Apr 25, 2009, 2:21:04 PM4/25/09
to
user923005 <dco...@connx.com> writes:
> On Apr 24, 9:40 pm, Han from China <autistic-pedan...@comp.lang.c>
> wrote:
>> 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?

--
Keith Thompson (The_Other_Keith) ks...@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"

Falcon Kirtaran

unread,
Apr 25, 2009, 2:20:08 PM4/25/09
to
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Carl wrote:


> azo...@gmail.com wrote:
>> COULD YOU PLEASE SOLVE THE FOLLOWING QUESTION.
>>
>> WRITE A PROGRAM IN C THAT WILL CALCULATE THE SUM OF EVEN NUMBERS FROM
>> 0 TO 20?
>

> 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-----

Han from China

unread,
Apr 25, 2009, 3:07:16 PM4/25/09
to
Keith Thompson wrote:
> Why are you feeding the trolls?

Let's see how many "fair and reasonable" people call out the above
unprovoked trolling attack from Thompson. He has a habit of
being the one to initiate insults against me in threads, as I
have started pointing out in recent weeks while refraining from
being aggressive in return.

Don't talk to me about community values and what's "right" when
you're happy to let Thompson try to ostracize people on this
newsgroup. If nobody sees a need to call out the above unprovoked
attack, then this whole debate about what's "right" when it comes
to OPs asking homework questions is finished, as far as I'm
concerned, because there's no moral compass on this group anyway.

Falcon Kirtaran

unread,
Apr 25, 2009, 3:06:10 PM4/25/09
to
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

azo...@gmail.com wrote:


> 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-----

Richard

unread,
Apr 25, 2009, 3:11:34 PM4/25/09
to
Falcon Kirtaran <falco...@pgpkey.iridiumlinux.org> writes:

> Carl wrote:
>> azo...@gmail.com wrote:
>>> COULD YOU PLEASE SOLVE THE FOLLOWING QUESTION.
>>>
>>> WRITE A PROGRAM IN C THAT WILL CALCULATE THE SUM OF EVEN NUMBERS FROM
>>> 0 TO 20?
>>
>> 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
>
>

Why?

Falcon Kirtaran

unread,
Apr 25, 2009, 3:09:09 PM4/25/09
to
-----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-----

Richard

unread,
Apr 25, 2009, 3:15:14 PM4/25/09
to
Falcon Kirtaran <falco...@pgpkey.iridiumlinux.org> writes:

Actually it's pretty ugly and wouldn't pass a first year code review.

>
> --
> --Falcon Darkstar Christopher Momot
> --

> --OpenPGP: (7902:4457) 9282:A431
>
>

--

Falcon Kirtaran

unread,
Apr 25, 2009, 3:15:10 PM4/25/09
to
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

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-----

Kenny McCormack

unread,
Apr 25, 2009, 4:46:00 PM4/25/09
to
In article <fbf06796f16619ea...@pseudo.borked.net>,

Han from China <autistic...@comp.lang.c> wrote:
...
>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.

Richard Tobin

unread,
Apr 25, 2009, 5:56:37 PM4/25/09
to
In article <75ghf5F...@mid.individual.net>,
osmium <r124c...@comcast.net> wrote:

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
--
Please remember to mention me / in tapes you leave behind.

Harald van Dijk

unread,
Apr 25, 2009, 7:09:34 PM4/25/09
to
Richard Tobin wrote:
> In article <75ghf5F...@mid.individual.net>,
> osmium <r124c...@comcast.net> wrote:

Why did you snip the attribution line for the below, which was present in
osmium's message?

>>> 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".
>
> 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.

Richard Tobin

unread,
Apr 25, 2009, 9:51:55 PM4/25/09
to
In article <gt057c$4mb$1...@news.motzarella.org>,

Harald van Dijk <tru...@gmail.com> wrote:

>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.

>> 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.

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.

CBFalconer

unread,
Apr 25, 2009, 10:34:37 PM4/25/09
to
Harald van D?k wrote:
> 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?

--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home.att.net>
Try the download section.


CBFalconer

unread,
Apr 25, 2009, 10:21:08 PM4/25/09
to
Lew Pitcher wrote:

> CBFalconer (cbfal...@yahoo.com) wrote:
>> azo...@gmail.com wrote:
>>>
>>> COULD YOU PLEASE SOLVE THE FOLLOWING QUESTION.
>>>
>>> WRITE A PROGRAM IN C THAT WILL CALCULATE THE SUM OF EVEN NUMBERS
>>> FROM 0 TO 20?
>>
>> #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;
>> }
>
> 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.

pete

unread,
Apr 25, 2009, 11:23:56 PM4/25/09
to
CBFalconer wrote:
> Harald van D?k wrote:
>> 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]

--
pete

CBFalconer

unread,
Apr 25, 2009, 11:52:48 PM4/25/09
to

I find no such section in either n869 or n1256.

Keith Thompson

unread,
Apr 26, 2009, 1:10:08 AM4/26/09
to
CBFalconer <cbfal...@yahoo.com> writes:
> pete wrote:
>> CBFalconer wrote:
>>> 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.

Harald van Dijk

unread,
Apr 26, 2009, 3:52:45 AM4/26/09
to
> In article <gt057c$4mb$1...@news.motzarella.org>,
> Harald van Dijk <tru...@gmail.com> wrote:
>
>>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.
>
>>> 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.
>
> 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?

Richard Tobin

unread,
Apr 26, 2009, 6:00:59 AM4/26/09
to
In article <gt13s6$j36$1...@news.motzarella.org>,

No, I would hope it would give me a more serious diagnostic! Though
a quick test suggests that gcc doesn't.

CBFalconer

unread,
Apr 26, 2009, 6:26:55 PM4/26/09
to
Keith Thompson wrote:
> CBFalconer <cbfal...@yahoo.com> writes:
>> pete wrote:
>>> CBFalconer wrote:
>>>> 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.

Now I see what I did. I searched for 7.2, not 7.26. Sloppy.

It is loading more messages.
0 new messages