Jump to content

C Program that counts total prime number

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
3 replies to this topic

#1
exe101

exe101

    Newbie

  • Members
  • Pip
  • 1 posts
I need to write c program which would count total numbers of prime between 0 & input value. I cannot use scanf so I must write main function. using command line argument..
Please Please Help Me

#2
davidthefat

davidthefat

    Learning Programmer

  • Members
  • PipPipPip
  • 82 posts
Isnt this cheating?

#3
MerakSpielman

MerakSpielman

    Learning Programmer

  • Members
  • PipPipPip
  • 44 posts
I don't think it's quite right for us to code your entire assignment for you...

But you'll find it much easier if you map it out with some sort of pseudocode first. Just sentence-by-sentence, in plain English, describe what your program needs to do. Something like this:

Receive input from user.
Check if input is valid.
Check if number is prime (have to determine algorithm - the core of the assignment)
Check if number-1 is prime...number-2... and so on until you reach 1.
If/when a prime number is detected, increment a counter by one.
Display results.


The algorithm would be the hard part. You have to ask yourself how you would determine whether a number was prime, using pencil and paper. What techniques would you use? What would your process be? Then write a function that does that process.

#4
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
What do you have so far?
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog