Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. 1000!

1000!

Scheduled Pinned Locked Moved C#
csharphelp
23 Posts 12 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A albCode

    int i,f; f=1; string factorial=""; for (i=1; i<=1000;i++) { f= f*i; factorial = f.ToString(); //additional /*if(i==33) { break; } */ } this.label1.Text = factorial; but u can get factorial until 33 otherwise 1000! gives u result 0 (zero) _____________________ Proud to be Albanian _____________________

    D Offline
    D Offline
    Dave Kreskowiak
    wrote on last edited by
    #14

    Congratulations!! You just did his homework for him!! And WOW, he didn't learn a damn thing!! :laugh: RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

    1 Reply Last reply
    0
    • S spin vector

      You need to use Stirling's formula, which asymptotically goes as n^n e^(-n). I'd prob take the log of this as a first calculation, or do something to avoid the n^n.

      S Offline
      S Offline
      Steve Pullan
      wrote on last edited by
      #15

      nyc_user wrote:

      You need to use Stirling's formula,

      Yes but... this is an approximation (admittedly with an error approaching 1/n^2 for n=1000) and won't be good enough if the exact value is required. ...Steve 1. quod erat demonstrandum 2. "Give a man a fish and you've fed him for a day. Teach him how to fish and you've fed him for life." I read that somewhere once :-) (Translation: I'll show you the way, but not write the code for you.)

      S 1 Reply Last reply
      0
      • A albCode

        int i,f; f=1; string factorial=""; for (i=1; i<=1000;i++) { f= f*i; factorial = f.ToString(); //additional /*if(i==33) { break; } */ } this.label1.Text = factorial; but u can get factorial until 33 otherwise 1000! gives u result 0 (zero) _____________________ Proud to be Albanian _____________________

        S Offline
        S Offline
        Steve Pullan
        wrote on last edited by
        #16

        albCode wrote:

        but u can get factorial until 33 otherwise 1000! gives u result 0 (zero)

        The problem is that you've defined f as an int. You'll need to use a different data type. ...Steve 1. quod erat demonstrandum 2. "Give a man a fish and you've fed him for a day. Teach him how to fish and you've fed him for life." I read that somewhere once :-) (Translation: I'll show you the way, but not write the code for you.)

        A 1 Reply Last reply
        0
        • S Steve Pullan

          nyc_user wrote:

          You need to use Stirling's formula,

          Yes but... this is an approximation (admittedly with an error approaching 1/n^2 for n=1000) and won't be good enough if the exact value is required. ...Steve 1. quod erat demonstrandum 2. "Give a man a fish and you've fed him for a day. Teach him how to fish and you've fed him for life." I read that somewhere once :-) (Translation: I'll show you the way, but not write the code for you.)

          S Offline
          S Offline
          spin vector
          wrote on last edited by
          #17

          That's virtually an absurd comment. The guy didn't give a type, so I might guess a double (or long would be better). Moreover, the leading coefficietly are easily googlable. If he wants all the digits down to the decimal point then that's a completely different problem. ;P

          S 1 Reply Last reply
          0
          • S spin vector

            That's virtually an absurd comment. The guy didn't give a type, so I might guess a double (or long would be better). Moreover, the leading coefficietly are easily googlable. If he wants all the digits down to the decimal point then that's a completely different problem. ;P

            S Offline
            S Offline
            Steve Pullan
            wrote on last edited by
            #18

            nyc_user wrote:

            That's virtually an absurd comment.

            Absurd? Hmmm....

            nyc_user wrote:

            The guy didn't give a type, so I might guess a double (or long would be better).

            The answer to 1000! is a whole number. So my comment still stands. Stirling's formula approximates the actual value (albeit a very good approximation) - there is some error involved.

            nyc_user wrote:

            If he wants all the digits down to the decimal point then that's a completely different problem.

            Yep I agree, however since he has not given us any more information on the assignment question, this discussion is academic. :) ...Steve 1. quod erat demonstrandum 2. "Give a man a fish and you've fed him for a day. Teach him how to fish and you've fed him for life." I read that somewhere once :-) (Translation: I'll show you the way, but not write the code for you.)

            S 1 Reply Last reply
            0
            • S Steve Pullan

              nyc_user wrote:

              That's virtually an absurd comment.

              Absurd? Hmmm....

              nyc_user wrote:

              The guy didn't give a type, so I might guess a double (or long would be better).

              The answer to 1000! is a whole number. So my comment still stands. Stirling's formula approximates the actual value (albeit a very good approximation) - there is some error involved.

              nyc_user wrote:

              If he wants all the digits down to the decimal point then that's a completely different problem.

              Yep I agree, however since he has not given us any more information on the assignment question, this discussion is academic. :) ...Steve 1. quod erat demonstrandum 2. "Give a man a fish and you've fed him for a day. Teach him how to fish and you've fed him for life." I read that somewhere once :-) (Translation: I'll show you the way, but not write the code for you.)

              S Offline
              S Offline
              Steini kallinn
              wrote on last edited by
              #19

              Acording to the answer generated from Maple 10, I don't think a small litle program is going to solve this...

              1000! =
              402387260077093773543702433923003985719374864210714632543799910429938512398
              629020592044208486969404800479988610197196058631666872994808558901323829669
              944590997424504087073759918823627727188732519779505950995276120874975462497
              043601418278094646496291056393887437886487337119181045825783647849977012476
              632889835955735432513185323958463075557409114262417474349347553428646576611
              667797396668820291207379143853719588249808126867838374559731746136085379534
              524221586593201928090878297308431392844403281231558611036976801357304216168
              747609675871348312025478589320767169132448426236131412508780208000261683151
              027341827977704784635868170164365024153691398281264810213092761244896359928
              705114964975419909342221566832572080821333186116811553615836546984046708975
              602900950537616475847728421889679646244945160765353408198901385442487984959
              953319101723355556602139450399736280750137837615307127761926849034352625200
              015888535147331611702103968175921510907788019393178114194545257223865541461
              062892187960223838971476088506276862967146674697562911234082439208160153780
              889893964518263243671616762179168909779911903754031274622289988005195444414
              282012187361745992642956581746628302955570299024324153181617210465832036786
              906117260158783520751516284225540265170483304226143974286933061690897968482
              590125458327168226458066526769958652682272807075781391858178889652208164348
              344825993266043367660176999612831860788386150279465955131156552036093988180
              612138558600301435694527224206344631797460594682573103790084024432438465657
              245014402821885252470935190620929023136493273497565513958720559654228749774
              011413346962715422845862377387538230483865688976461927383814900140767310446
              640259899490222221765904339901886018566526485061799702356193897017860040811
              889729918311021171229845901641921068884387121855646124960798722908519296819
              372388642614839657382291123125024186649353143970137428531926649875337218940
              694281434118520158014123344828015051399694290153483077644569099073152433278
              288269864602789864321139083506217095002597389863554277196742822248757586765
              752344220207573630569498825087968928162753848863396909959826280956121450994
              871701244516461260379029309120889086942028510640182154399457156805941872748
              998094254742173582401063677404595741785160829230135358081840096996372524230
              560855903700624271243416909004153690105933983835777939410970027753472000000
              000000000000000000000000000000000000000000000

              S 1 Reply Last reply
              0
              • S Steve Pullan

                albCode wrote:

                but u can get factorial until 33 otherwise 1000! gives u result 0 (zero)

                The problem is that you've defined f as an int. You'll need to use a different data type. ...Steve 1. quod erat demonstrandum 2. "Give a man a fish and you've fed him for a day. Teach him how to fish and you've fed him for life." I read that somewhere once :-) (Translation: I'll show you the way, but not write the code for you.)

                A Offline
                A Offline
                albCode
                wrote on last edited by
                #20

                "u have right" (maybe) _____________________ Proud to be Albanian _____________________

                1 Reply Last reply
                0
                • E eggie5

                  HAAHA are you indian? /\ |_ E X E GG

                  A Offline
                  A Offline
                  albCode
                  wrote on last edited by
                  #21

                  Dude if u asking me do i am indian. the answer is false. I am Europen(Kosovo-Albanian) ;) _____________________ Proud to be Albanian _____________________

                  1 Reply Last reply
                  0
                  • S Sean Michael Murphy

                    Professor Sharada Ulhas wrote:

                    Sincelery yours, Computer Information conSciences Professor and grader, Sharada Ulhas

                    Professor? If this is an example of an assignment at your university, you may want to put a "stop" on that tuition cheque... Share and enjoy. Sean

                    P Offline
                    P Offline
                    prrusa
                    wrote on last edited by
                    #22

                    >If this is an example of an assignment at your university, you may want to >put a "stop" on that tuition cheque... Could you please elaborate? I'm dying to find out how you came to this conclusion from the info you had? Please hurry with your reply, we may have stumbled upon a savant.

                    1 Reply Last reply
                    0
                    • S Steini kallinn

                      Acording to the answer generated from Maple 10, I don't think a small litle program is going to solve this...

                      1000! =
                      402387260077093773543702433923003985719374864210714632543799910429938512398
                      629020592044208486969404800479988610197196058631666872994808558901323829669
                      944590997424504087073759918823627727188732519779505950995276120874975462497
                      043601418278094646496291056393887437886487337119181045825783647849977012476
                      632889835955735432513185323958463075557409114262417474349347553428646576611
                      667797396668820291207379143853719588249808126867838374559731746136085379534
                      524221586593201928090878297308431392844403281231558611036976801357304216168
                      747609675871348312025478589320767169132448426236131412508780208000261683151
                      027341827977704784635868170164365024153691398281264810213092761244896359928
                      705114964975419909342221566832572080821333186116811553615836546984046708975
                      602900950537616475847728421889679646244945160765353408198901385442487984959
                      953319101723355556602139450399736280750137837615307127761926849034352625200
                      015888535147331611702103968175921510907788019393178114194545257223865541461
                      062892187960223838971476088506276862967146674697562911234082439208160153780
                      889893964518263243671616762179168909779911903754031274622289988005195444414
                      282012187361745992642956581746628302955570299024324153181617210465832036786
                      906117260158783520751516284225540265170483304226143974286933061690897968482
                      590125458327168226458066526769958652682272807075781391858178889652208164348
                      344825993266043367660176999612831860788386150279465955131156552036093988180
                      612138558600301435694527224206344631797460594682573103790084024432438465657
                      245014402821885252470935190620929023136493273497565513958720559654228749774
                      011413346962715422845862377387538230483865688976461927383814900140767310446
                      640259899490222221765904339901886018566526485061799702356193897017860040811
                      889729918311021171229845901641921068884387121855646124960798722908519296819
                      372388642614839657382291123125024186649353143970137428531926649875337218940
                      694281434118520158014123344828015051399694290153483077644569099073152433278
                      288269864602789864321139083506217095002597389863554277196742822248757586765
                      752344220207573630569498825087968928162753848863396909959826280956121450994
                      871701244516461260379029309120889086942028510640182154399457156805941872748
                      998094254742173582401063677404595741785160829230135358081840096996372524230
                      560855903700624271243416909004153690105933983835777939410970027753472000000
                      000000000000000000000000000000000000000000000

                      S Offline
                      S Offline
                      Steve Pullan
                      wrote on last edited by
                      #23

                      Good one! My comments really are academic :-) ...Steve 1. quod erat demonstrandum 2. "Give a man a fish and you've fed him for a day. Teach him how to fish and you've fed him for life." I read that somewhere once :-) (Translation: I'll show you the way, but not write the code for you.)

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups