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.
1-develop a flowchart and then write a c program to display all prime
number less than the number entered by the user.
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);
scanf ("%u", &limit);
printf ("The prime numbers less than %u "
"are listed below:\n", limit);
for (value = 2; value < limit; ++value)
printf ("\t%u\n", value);
printf ("... along with a few false positives.\n");
return 0;
}
>1-develop a flowchart and then write a c program to display all prime
>number less than the number entered by the user.
>
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?
scanf ("%u", &limit);
printf ("The prime numbers less than %u "
"are listed below:\n", limit);
for (value = 2; value < limit; ++value)
printf ("\t%u\n", value);
printf ("... along with a few false positives.\n");
return 0;
}
>
In article <g2os8n$oq1$1@r egistered.motza rella.org>,
santosh <santosh.k83@gm ail.comwrote:
>Eric Sosman wrote:
>printf ("Number, please? ");
>fflush (0);
>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.
--
"There is nothing so bad but it can masquerade as moral."
-- Walter Lippmann
On Wed, 11 Jun 2008 16:08:51 +0000, Walter Roberson wrote:
In article <g2os8n$oq1$1@r egistered.motza rella.org>, santosh
<santosh.k83@gm ail.comwrote:
>>Eric Sosman wrote:
>
>>printf ("Number, please? ");
>>fflush (0);
>
>>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.
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.
In article <g2os8n$oq1$1@r egistered.motza rella.org>,
santosh <santosh.k83@gm ail.comwrote:
>Eric Sosman wrote:
>
>>printf ("Number, please? ");
>>fflush (0);
>
>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.
"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 ...
>>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.
>
"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').
--
Keith Thompson (The_Other_Keit h) kst-u@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
>>Eric Sosman wrote:
>>>
>>>printf ("Number, please? ");
>>>fflush (0);
>>>
>>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.
>
"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 ...
An elegant objective, and quite possibly achieved, since the guilty
student has not reappeared, and so may have taken your method and
submitted it.
--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home .att.net>
Try the download section.
On Jun 11, 1:44 am, sameer <pawan.prajapat i...@gmail.comw rote:
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;
}
Comment