C Lessons Project

V

Vladimir S. Oka

Learn C programming from these daily lessons I found. They're eleven
days ahead of you already so get busy...

http://www.visualcmaniac.com

DON'T! Unless you want to learn how to write *bad* C-like programs.

And here's why ("Lesson" 12):
#include <stdio.h>
#include <math.h>

Not necessary to include math.h as it's not used below
void main() {

After this, all bets are off. Watch pink pigs crawl out your ears
(undefined behaviour, `main` has to return `int`).
int i, n, prime=1; // prime is true

Comments like these are OK in C99.
printf("Input natural number :");

Not terminating `printf` with \n makes it possible for the
implementation to NOT print anything out (at least not before firts \n
it sees).
scanf("%d", &n);

No error checking. What if user enters something that's not an integer.
Even if integer is entered, what if it's negative?
for( i=2; i<= n-1; i++) {

if( n % i == 0 ) { // also possible to state if(!(n % i))

Much better to parenthesise appropriatelly:

if( (n % i) == 0 ) { // also possible to
state if(!(n % i))
prime =0; // prime is now false
break;

}
}

if( prime )

printf("%d is prime number !\n", n);

else

printf("%d isn't prime number!\n", n);

}

Spacing is atrocious (or sloppy, if you will).

I didn't check whether the algorithmu used is actually correct either.
 
R

Richard Heathfield

(e-mail address removed) said:
Learn C programming from these daily lessons I found. They're eleven
days ahead of you already so get busy...

http://www.visualcmaniac.com

If these lessons are supposed to teach C, they fail. If they are supposed to
teach some platform-specific variant of C, they are off-topic here.
 
P

pemo

Comments like these are OK in C99.


Not terminating `printf` with \n makes it possible for the
implementation to NOT print anything out (at least not before firts \n
it sees).

<snip>

Could you explain this please ... seems like you're saying that, say,

printf("Enter a number >");

might result in printf not outputting anything?
 
R

Richard Heathfield

pemo said:
Could you explain this please ... seems like you're saying that, say,

printf("Enter a number >");

might result in printf not outputting anything?

Right, because stdout is typically line-buffered.

fflush(stdout); will ensure that the display occurs even without the
newline.
 
D

Default User

Learn C programming from these daily lessons I found. They're eleven
days ahead of you already so get busy...


Oddly, the lessons you "found" seem to have been posted by someone
named Vurdlak. That's your name too! What a coincidence.



Brian
 
K

Keith Thompson

Learn C programming from these daily lessons I found. They're eleven
days ahead of you already so get busy...

http://[snip]

I don't think I've ever seen an "I've found this web site" posting
where the poster isn't actually the author of the web site. Sure
enough, every entry was posted by someone named "Vurdlak".

Lying to us about your own web site isn't a good start.

Filling your site with bad code and system-specific assumptions
doesn't exactly impress me either.

Learn C before you try to teach it.
 
C

CBFalconer

pemo said:
.... snip ...

<snip>

Could you explain this please ... seems like you're saying
that, say,

printf("Enter a number >");

might result in printf not outputting anything?
==============
*Not a pedant*
==============

Exactly. However explanations require pedantry, so we won't
inflict that on you.

--
"If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson
More details at: <http://cfaj.freeshell.org/google/>
Also see <http://www.safalra.com/special/googlegroupsreply/>
 

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

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top