![]() |
![]() |
#1 |
Apr 2005
2×19 Posts |
![]()
I just wanted to create a programme in C, which will count up from 1 to 20.
Heres the script, but for some reason, theres a mistake and it won't work, I don't see whats wrong with it. Can you find the mistake :surprised : Code:
main() { int Nth; int lower, upper, step; upper = 20; lower = 1; step = 1; /* step size */ Nth = lower; while (Nth <= upper){ Nth = Nth + step; printf("%d", Nth); getchar(); } } |
![]() |
![]() |
![]() |
#2 |
Apr 2005
2×19 Posts |
![]()
Don't bother, I found the mistake.
![]() ![]() |
![]() |
![]() |
![]() |
#3 |
Jun 2003
The Texas Hill Country
32×112 Posts |
![]() Code:
main() { int Nth; int lower, upper, step; upper = 20; lower = 1; step = 1; /* step size */ Nth = lower; while (Nth <= upper){ Nth = Nth + step; printf("%d", Nth); getchar(); } } Did you try using the C compiler? Did you provide input? What did happen? I'm guessing that you're hung on buffered I/O. See `man 3 fflush`. I also notice that it will print 2-21 since you have incremented before the print. And you may find the formatting unsatisfactory. |
![]() |
![]() |
![]() |
#4 |
Aug 2002
26·5 Posts |
![]()
main should return an int
|
![]() |
![]() |
![]() |
#5 | |
Jun 2003
The Texas Hill Country
21018 Posts |
![]() Quote:
It also should have argc and argv arguments ..... But I perceive that the inquirer is not yet ready for such subtleties. |
|
![]() |
![]() |
![]() |
#6 |
Apr 2005
2·19 Posts |
![]()
Yes, I know I left the arguments out at the very beginning. And I said so.
![]() |
![]() |
![]() |
![]() |
#7 | |
Jun 2003
The Texas Hill Country
44116 Posts |
![]() Quote:
|
|
![]() |
![]() |
![]() |
Thread Tools | |
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Deliberate mistake? | Nick | Forum Feedback | 6 | 2016-01-14 11:53 |
Small mistake | tomgreep | Information & Answers | 4 | 2014-06-09 20:33 |
Somebody made a numerical mistake | Arkadiusz | Math | 20 | 2009-12-22 16:07 |
ECM efforts mistake? | 10metreh | mersennewiki | 1 | 2008-12-28 13:31 |
Mistake in List of Primes | rogue | Sierpinski/Riesel Base 5 | 1 | 2007-02-23 00:35 |