mersenneforum.org  

Go Back   mersenneforum.org > Extra Stuff > Programming

Reply
 
Thread Tools
Old 2005-04-08, 12:40   #1
Vijay
 
Apr 2005

2×19 Posts
Default A very simple mistake...

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();
    }
}
Vijay is offline   Reply With Quote
Old 2005-04-08, 12:43   #2
Vijay
 
Apr 2005

2×19 Posts
Default

Don't bother, I found the mistake.
Vijay is offline   Reply With Quote
Old 2005-04-08, 13:02   #3
Wacky
 
Wacky's Avatar
 
Jun 2003
The Texas Hill Country

32×112 Posts
Default

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();
    }
}
"it won't work" isn't a very helpful description of the situation.
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.
Wacky is offline   Reply With Quote
Old 2005-04-09, 01:27   #4
ColdFury
 
ColdFury's Avatar
 
Aug 2002

26·5 Posts
Default

main should return an int
ColdFury is offline   Reply With Quote
Old 2005-04-09, 02:07   #5
Wacky
 
Wacky's Avatar
 
Jun 2003
The Texas Hill Country

21018 Posts
Default

Quote:
Originally Posted by ColdFury
main should return an int
SHOULD ---
It also should have argc and argv arguments .....

But I perceive that the inquirer is not yet ready for such subtleties.
Wacky is offline   Reply With Quote
Old 2005-04-09, 10:52   #6
Vijay
 
Apr 2005

2·19 Posts
Arrow I know now

Yes, I know I left the arguments out at the very beginning. And I said so.
Vijay is offline   Reply With Quote
Old 2005-04-09, 11:39   #7
Wacky
 
Wacky's Avatar
 
Jun 2003
The Texas Hill Country

44116 Posts
Default

Quote:
Originally Posted by Vijay
Yes, I know I left the arguments out at the very beginning. And I said so.
You did? I don't see where you declared that omission.
Wacky is offline   Reply With Quote
Reply

Thread Tools


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

All times are UTC. The time now is 03:15.


Sun Sep 24 03:15:33 UTC 2023 up 11 days, 57 mins, 0 users, load averages: 1.27, 1.14, 1.08

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2023, Jelsoft Enterprises Ltd.

This forum has received and complied with 0 (zero) government requests for information.

Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation.
A copy of the license is included in the FAQ.

≠ ± ∓ ÷ × · − √ ‰ ⊗ ⊕ ⊖ ⊘ ⊙ ≤ ≥ ≦ ≧ ≨ ≩ ≺ ≻ ≼ ≽ ⊏ ⊐ ⊑ ⊒ ² ³ °
∠ ∟ ° ≅ ~ ‖ ⟂ ⫛
≡ ≜ ≈ ∝ ∞ ≪ ≫ ⌊⌋ ⌈⌉ ∘ ∏ ∐ ∑ ∧ ∨ ∩ ∪ ⨀ ⊕ ⊗ 𝖕 𝖖 𝖗 ⊲ ⊳
∅ ∖ ∁ ↦ ↣ ∩ ∪ ⊆ ⊂ ⊄ ⊊ ⊇ ⊃ ⊅ ⊋ ⊖ ∈ ∉ ∋ ∌ ℕ ℤ ℚ ℝ ℂ ℵ ℶ ℷ ℸ 𝓟
¬ ∨ ∧ ⊕ → ← ⇒ ⇐ ⇔ ∀ ∃ ∄ ∴ ∵ ⊤ ⊥ ⊢ ⊨ ⫤ ⊣ … ⋯ ⋮ ⋰ ⋱
∫ ∬ ∭ ∮ ∯ ∰ ∇ ∆ δ ∂ ℱ ℒ ℓ
𝛢𝛼 𝛣𝛽 𝛤𝛾 𝛥𝛿 𝛦𝜀𝜖 𝛧𝜁 𝛨𝜂 𝛩𝜃𝜗 𝛪𝜄 𝛫𝜅 𝛬𝜆 𝛭𝜇 𝛮𝜈 𝛯𝜉 𝛰𝜊 𝛱𝜋 𝛲𝜌 𝛴𝜎𝜍 𝛵𝜏 𝛶𝜐 𝛷𝜙𝜑 𝛸𝜒 𝛹𝜓 𝛺𝜔