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. Hello folks

Hello folks

Scheduled Pinned Locked Moved C#
tutorial
28 Posts 9 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.
  • G Guffa

    Alternatively without using strings at all:

    public int CrossSum(int value) {
    int sum = 0;
    while (value > 0) {
    sum += value % 10;
    value /= 10;
    }
    return sum;
    }

    Frankly, Estarta, if you are applying for a job as a programmer, you should be able to write something simple as this yourself.

    --- single minded; short sighted; long gone;

    M Offline
    M Offline
    MoeInsairat
    wrote on last edited by
    #19

    Thats true. Thanks :)

    Estarta

    1 Reply Last reply
    0
    • M MoeInsairat

      I Know the basics.. !! int x= int.Parse(Input.Text); int t =0; string i = x.ToString(); for(int y=0;yEstarta

      R Offline
      R Offline
      Russell Jones
      wrote on last edited by
      #20

      that's quite a different question from the one you asked at the start :confused: Can i suggest not using the letter i to denote a string, even if it does contain the string representation of an integer. You should use Parse or TryParse on the input to make sure that the number can be represented as a number. Russell

      1 Reply Last reply
      0
      • M MoeInsairat

        I Know the basics.. !! int x= int.Parse(Input.Text); int t =0; string i = x.ToString(); for(int y=0;yEstarta

        S Offline
        S Offline
        Stefan Troschuetz
        wrote on last edited by
        #21

        Estarta wrote:

        This is wat i did!!and its working, but wat im asking is there is anyway i can do it without Parse the int to String?

        So why didn't you show us the code and asked exactly that question in the first place? Why did you told us "i've tried, but i can't get it done!"?


        "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook

        www.troschuetz.de

        M 1 Reply Last reply
        0
        • S Stefan Troschuetz

          Estarta wrote:

          This is wat i did!!and its working, but wat im asking is there is anyway i can do it without Parse the int to String?

          So why didn't you show us the code and asked exactly that question in the first place? Why did you told us "i've tried, but i can't get it done!"?


          "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook

          www.troschuetz.de

          M Offline
          M Offline
          MoeInsairat
          wrote on last edited by
          #22

          bcuz i've tried and maybe my question wasn't so clear.. i was trying to tell u guys i want the answer without parsing the input into integers.. anyway i got the answer thanks for ur time

          Estarta

          S 1 Reply Last reply
          0
          • M MoeInsairat

            Well thanks again for the reply. but you know you don't have to say such things if you can erase my account so do it!! but don't act like the YOU ARE THE BEST or i dont know wats the matter with u!!! i asked a question AND I DON'T KNOW THE ANSWER nth to be shamed of!!! and btw i`m a software engineer we didn't took PROGRAMMING LANGUAGES as u did !! we only took the software engineering syuff and rational rose!! You dont even deserve my reply!!! Good bye MR

            Estarta

            C Offline
            C Offline
            Colin Angus Mackay
            wrote on last edited by
            #23

            Estarta wrote:

            i`m a software engineer we didn't took PROGRAMMING LANGUAGES as u did !! we only took the software engineering syuff and rational rose!!

            What kind of crazy Software Engineering course did you do? The university I went to offered SoftEng courses and they included C++ and COBOL (it was a while ago) in the curriculum.


            Upcoming events: * Edinburgh: Web Security Conference Day for Windows Developers (12th April) * Glasgow: Introduction to AJAX (2nd May), SQL Server, Mock Objects My website

            P 1 Reply Last reply
            0
            • M MoeInsairat

              bcuz i've tried and maybe my question wasn't so clear.. i was trying to tell u guys i want the answer without parsing the input into integers.. anyway i got the answer thanks for ur time

              Estarta

              S Offline
              S Offline
              Stefan Troschuetz
              wrote on last edited by
              #24

              Estarta wrote:

              my question wasn't so clear

              Certainly not.

              Estarta wrote:

              i was trying to tell u guys i want the answer without parsing the input into integers.

              You never even clearly stated that the input is the string representation of an integer. By the way, there is no way I can think of that wouldn't require you to do some parsing. You cannot do mathematical computations with strings.


              "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook

              www.troschuetz.de

              M 1 Reply Last reply
              0
              • S Stefan Troschuetz

                Estarta wrote:

                my question wasn't so clear

                Certainly not.

                Estarta wrote:

                i was trying to tell u guys i want the answer without parsing the input into integers.

                You never even clearly stated that the input is the string representation of an integer. By the way, there is no way I can think of that wouldn't require you to do some parsing. You cannot do mathematical computations with strings.


                "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook

                www.troschuetz.de

                M Offline
                M Offline
                MoeInsairat
                wrote on last edited by
                #25

                private void Button1_Click(object sender, System.EventArgs e) { int x= int.Parse(Input.Text); int sum = 0; while (x > 0) { sum += x % 10; x /= 10; } Output.Text=sum.ToString(); } how about this one?

                Estarta

                S 1 Reply Last reply
                0
                • M MoeInsairat

                  private void Button1_Click(object sender, System.EventArgs e) { int x= int.Parse(Input.Text); int sum = 0; while (x > 0) { sum += x % 10; x /= 10; } Output.Text=sum.ToString(); } how about this one?

                  Estarta

                  S Offline
                  S Offline
                  Stefan Troschuetz
                  wrote on last edited by
                  #26

                  Estarta wrote:

                  how about this one?

                  Computes the sum of the digits of the number entered in Input control, but I gues you already know that. What is the actual question here. By the way, you should surround the Parse operation with a try-catch-block to catch the FormatException thrown when the Input control does not contain a valid string representation of an integer (or use TryParse when programming for Framework version > 1.1).


                  "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook

                  www.troschuetz.de

                  1 Reply Last reply
                  0
                  • C Colin Angus Mackay

                    Estarta wrote:

                    i`m a software engineer we didn't took PROGRAMMING LANGUAGES as u did !! we only took the software engineering syuff and rational rose!!

                    What kind of crazy Software Engineering course did you do? The university I went to offered SoftEng courses and they included C++ and COBOL (it was a while ago) in the curriculum.


                    Upcoming events: * Edinburgh: Web Security Conference Day for Windows Developers (12th April) * Glasgow: Introduction to AJAX (2nd May), SQL Server, Mock Objects My website

                    P Offline
                    P Offline
                    Pete OHanlon
                    wrote on last edited by
                    #27

                    COBOL - almost a good anagram.:laugh:

                    Deja View - the feeling that you've seen this post before.

                    1 Reply Last reply
                    0
                    • M MoeInsairat

                      Please i need this answer asap.. if i want to do a function that accepts INTEGERS number... then i wanna the sum of these integers.. for example if i entered 123.. the answer should be 6. Thanks in advance Regards

                      Estarta

                      D Offline
                      D Offline
                      David Crow
                      wrote on last edited by
                      #28

                      Are you referring to the digital root of a number?


                      "Approved Workmen Are Not Ashamed" - 2 Timothy 2:15

                      "Judge not by the eye but by the heart." - Native American Proverb

                      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