flowchart

S

sameer

1-develop a flowchart and then write a c program to display all prime
number less than the number entered by the user.
 
J

Joachim Schmitz

sameer said:
1-develop a flowchart and then write a c program to display all prime
number less than the number entered by the user.
homework alert!

Try it yourself first and show what you tried and were you got stuck

Bye, Jojo
 
C

Chris Dollin

sameer said:
1-develop a flowchart and then write a c program to display all prime
number less than the number entered by the user.

What benefit do you expect to gain from a flowchart?

Displaying all prime numbers less than some N is trivial. It's /not/
displaying /composite/ numbers that's hard ...
 
S

santosh

sameer said:
1-develop a flowchart and then write a c program to display all prime
number less than the number entered by the user.

What exactly do you expect from this post? Have you made an attempt
yourself? If so, post your code, however incomplete or ugly it may be.
I suppose you do know what prime numbers are? How would you solve the
second part of your problem with a pen and paper? Your maths textbook
should have algorithms for doing this. Try implementing them in C.
 
S

santosh

Eric said:
Flowcharts are difficult in monospaced text, so I'll leave
that part to you. Here's the program, though, with error- and
sanity-checking omitted for brevity:

#include <stdio.h>
int main(void) {
unsigned int limit;
unsigned int value;
printf ("Number, please? ");
fflush (0);

Can you tell me why you're using 0 instead of stdout?
 
W

Walter Roberson

Eric Sosman wrote:
Can you tell me why you're using 0 instead of stdout?

$ man fflush
When calling fflush, if stream is a null pointer, all files open for
writing only and all files open for update whose last operation was a
write are flushed.
 
H

Harald van Dijk

$ man fflush
When calling fflush, if stream is a null pointer, all files open
for writing only and all files open for update whose last operation
was a write are flushed.

That means fflush(0) is valid, not that it's a good idea. In this case, I
don't see the benefit to fflush(0) either, so I'm also curious for the
reason behind it.
 
K

Keith Thompson

Eric Sosman said:
"What he said." And my purpose was obfuscatory deviltry,
with a sneaking hope that it might survive all the way into
the O.P.'s homework submission, where it would likely elicit
santosh's question from the O.P.'s instructor and cause him
a well-deserved dose of embarrassment ...

Which won't happen now that you've admitted it in public. Oh, well.

Next time, consider fflush(L'\0').
 
A

Antoninus Twink

1-develop a flowchart and then write a c program to display all prime
number less than the number entered by the user.

#include <stdio.h>
#include <gmp.h>

int main(int argc, char **argv)
{
int status=0;

if(argc>1) {
mpz_t n,p;
mpz_init_set_si(p, 2);
if(mpz_init_set_str(n, argv[1], 10)==0) {
while(mpz_cmp(p, n) <= 0) {
mpz_out_str(stdout, 10, p);
puts("");
mpz_nextprime(p,p);
}
} else {
fputs("Invalid argument\n", stderr);
status=1;
}
mpz_clear(n);
mpz_clear(p);
} else {
fprintf(stderr, "Usage: %s n\nPrints the primes <= n\n", *argv);
status=2;
}
return status;
}
 
D

Don

1-develop a flowchart and then write a c program to display allprime
number less than the number entered by the user.

#include <stdio.h>

/* This program implements a blindingly fast O(n^n) algorithm
to find prime numbers, using an elegant recursive method. */
int _(int n, int m, int d, int t=0)
{
int r;
if (t) return d?1+_(n,m,d-1,d):n?_(n-1,m,m,n):0;
for(r=m!=n; d*(t<n); ++t)
r &= _(n,_(t,m,0,1),d-1)|!_(t,1,t);
return r*n;
}


/*------------------------------------------
Print primes up to the requested value
--------------------------------------------*/
int main(int argc, char* argv[])
{
int n,m;
scanf("%d",&m);
for(n = 2; n <= m; n++)
printf("%d is%s prime\n",n, _(n,1,n,0)?"":" not");
return 0;
}
 
K

Keith Thompson

CBFalconer said:
That sounds like a bug. How do you get lcc-win to report the error?

It's obviously an extension.

If lcc-win's conforming mode works correctly, it will issue a
diagnostic. In the absence of any evidence that it doesn't, I suggest
that speculating about *possible* bugs in lcc-win (or any other
compiler) is both off-topic and a waste of time. (Which is not to
imply that mentioning the extension in the first place was topical.0
 

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

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top