flowchart

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • sameer

    flowchart

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

    #2
    Re: flowchart

    sameer wrote:
    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


    Comment

    • Chris Dollin

      #3
      Re: flowchart

      sameer wrote:
      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 ...

      --
      "It would have to be enough." /Brokedown Palace/

      Hewlett-Packard Limited Cain Road, Bracknell, registered no:
      registered office: Berks RG12 1HN 690597 England

      Comment

      • santosh

        #4
        Re: flowchart

        sameer wrote:
        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.

        Comment

        • Eric Sosman

          #5
          Re: flowchart

          sameer wrote:
          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;
          }

          --
          Eric Sosman
          esosman@ieee-dot-org.invalid

          Comment

          • santosh

            #6
            Re: flowchart

            Eric Sosman wrote:
            sameer wrote:
            >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;
            }
            >

            Comment

            • Walter Roberson

              #7
              Re: flowchart

              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

              Comment

              • Harald van =?UTF-8?b?RMSzaw==?=

                #8
                Re: flowchart

                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.

                Comment

                • Eric Sosman

                  #9
                  Re: flowchart

                  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.
                  "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 ...

                  --
                  Eric.Sosman@sun .com

                  Comment

                  • Keith Thompson

                    #10
                    Re: flowchart

                    Eric Sosman <Eric.Sosman@su n.comwrites:
                    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.
                    >
                    "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"

                    Comment

                    • CBFalconer

                      #11
                      Re: flowchart

                      Eric Sosman wrote:
                      Walter Roberson wrote:
                      >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 ...
                      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.


                      ** Posted from http://www.teranews.com **

                      Comment

                      • rahul

                        #12
                        Re: flowchart

                        On Jun 11, 11:44 am, sameer <pawan.prajapat i...@gmail.comw rote:
                        1-develop a flowchart and then write a c program to display all prime
                        number less than the number entered by the user.
                        Try Sieve of Eratosthenes.

                        <weird>
                        You are using this as a homework forum and everyone is responding.
                        </weird>

                        Comment

                        • Chris Dollin

                          #13
                          Re: flowchart

                          rahul wrote:
                          On Jun 11, 11:44 am, sameer <pawan.prajapat i...@gmail.comw rote:
                          >1-develop a flowchart and then write a c program to display all prime
                          >number less than the number entered by the user.
                          >
                          Try Sieve of Eratosthenes.

                          <weird>
                          You are using this as a homework forum and everyone is responding.
                          </weird>
                          As a wise Narn said, "not all replies are answers".

                          --
                          "I am trying to say that you have no choice." /The Courts of Chaos/

                          Hewlett-Packard Limited Cain Road, Bracknell, registered no:
                          registered office: Berks RG12 1HN 690597 England

                          Comment

                          • Antoninus Twink

                            #14
                            Re: flowchart

                            On 11 Jun 2008 at 6:44, sameer wrote:
                            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(std out, 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;
                            }

                            Comment

                            • Don

                              #15
                              Re: flowchart

                              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

                              Working...