Search This Blog

This website completely moved to new domain. For latest content, visit www.programmingposts.com

Simple C# Program To Add Two Numbers / Integers


C# PROGRAM TO ADD TWO NUMBERS / INTEGERS :

using System;
 
namespace CsharpPrograms
{
    class Program
    {
        static void Main(string[] args)
        {
 
            int x;
            int y;
            int result;
            Console.Write("\n Enter the first number to be added: ");
            x=Convert.ToInt32(Console.ReadLine());
            Console.Write("\n Enter the second number to be added: ");
            y = Convert.ToInt32(Console.ReadLine());
            result = x + y;
            Console.Write("\n The sum of two numbers is: "+result);
            Console.ReadLine();
        }
    }
}

Output:


For C program: c program for adding two numbers / integers

39 comments:

  1. This blog awesome and i learn a lot about programming from here.The best thing about this blog is that you doing from beginning to experts level.

    Love from

    ReplyDelete
  2. It is really very helpful for us and I have gathered some important information from this blog.

    Mobile Application Development and Testing Training

    ReplyDelete
  3. how to add two numbers by getting the input from a text file and displaying in console window

    ReplyDelete
  4. 2
    12
    20
    21
    22
    23
    24
    .
    .
    .
    .
    .
    .
    the letter which shows 2 should be priented

    ReplyDelete
    Replies
    1. Hi,
      check this program, http://www.programmingposts.com/2016/09/csharp-program-to-count-digit-in-number.html

      Delete
  5. How to add two roman numerals which will show result in roman numerals only.

    ReplyDelete
  6. how to print two int values in console?

    ReplyDelete
  7. how to print a value by getting input from another project?

    ReplyDelete
    Replies
    1. sorry, i did not get you, can u please explain wat are u expecting ?

      Delete


  8. It is really a great work and the way in which u r sharing the knowledge is excellent.
    Thanks for helping me to understand basic concepts. As a beginner in Dot Net programming your post help me a lot.Thanks for your informative article. Dot Net Training in chennai | Dot Net Training in velachery

    ReplyDelete
  9. Given so much information in it. its very useful .perfect explanation about Dot net framework.Thanks for your valuable information. dot net training in chennai velachery | dot net training institute in velachery

    ReplyDelete
  10. The coding shared are very much useful My sincere thanks for sharing this post Please Continue to share this kind of post
    Dot Net Training in Chennai

    ReplyDelete
  11. really you had been shared very informative blog. before i read this blog i didn't have any knowledge about this but now i got some knowledge. so keep on sharing such kind of an interesting blog.
    dot net training in chennai

    ReplyDelete
  12. I admire the valuable information you offer in your articles. I will bookmark your blog and have my friends check up here often. I am quite sure they will learn lots of new stuff here than anybody else! Cloud Computing Training in Chennai | Salesforce Training in Chennai


    ReplyDelete
  13. using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;

    namespace ConsoleApplication2
    {
    class Program
    {

    static int a, b;

    public int addition()
    {
    return a + b;
    }

    public int substraction()
    {
    return a - b;
    }

    public int division()
    {
    return a / b;
    }
    public int multiplication()
    {
    return a * b;
    }

    public void desplay()
    {

    Console.WriteLine("Addition="+addition());
    Console.WriteLine("Substraction=" + substraction());
    Console.WriteLine("Division=" + division());
    Console.WriteLine("Multiplication=" + multiplication());
    }
    public void add_num()
    {
    Console.WriteLine("Enter first digit");
    a = Convert.ToInt32(Console.ReadLine());
    Console.WriteLine("Enter second digit");
    b = Convert.ToInt32(Console.ReadLine());
    }
    static void Main(string[] args)
    {

    Program pr = new Program();
    pr.add_num();
    pr.addition();
    pr.substraction();
    pr.division();
    pr.multiplication();
    pr.desplay();
    Console.ReadLine();
    }

    }
    }

    ReplyDelete
  14. what if user enter a decimal value

    ReplyDelete
    Replies
    1. Convert.ToInt32(Console.ReadLine()) will convert your input to int.
      use Convert.ToDecimal(Console.ReadLine()) for decimal numbers

      Delete
  15. Wonderful post. I am learning so many things from your blog.keep posting.
    PHP Online Training
    Pega Online Training
    Oracle Soa Online Training

    ReplyDelete
  16. how will we perform addition of two numbers entering number without user in c#???
    Please Help me !

    ReplyDelete
  17. looking for good informatoin learning so many things.
    c sharp training in chennai

    ReplyDelete
  18. Some us know all relating to the compelling medium you present powerful steps on this blog and therefore strongly encourage contribution from other ones on this subject while our own child is truly discovering a great deal. Have fun with the remaining portion of the year.
    Core Java interview questions and answers

    Java training in Chennai | Java training in Tambaram

    Java training in Chennai | Java training in Velachery

    Java training in Chennai | Java training in Omr

    ReplyDelete
  19. This is most informative and also this post most user friendly and super navigation to all posts... Thank you so much for giving this information to me.

    rpa training in chennai
    rpa training in bangalore
    rpa course in bangalore
    best rpa training in bangalore
    rpa online training

    ReplyDelete
  20. Your good knowledge and kindness in playing with all the pieces were very useful. I don’t know what I would have done if I had not encountered such a step like this.
    python course in pune
    python course in chennai
    python course in Bangalore

    ReplyDelete
  21. Great Article… I love to read your articles because your writing style is too good, its is very very helpful for all of us and I never get bored while reading your article because, they are becomes a more and more interesting from the starting lines until the end.
    Best Devops Training in pune
    excel advanced excel training in bangalore
    Devops Training in Chennai

    ReplyDelete
  22. When I initially commented, I clicked the “Notify me when new comments are added” checkbox and now each time a comment is added I get several emails with the same comment. Is there any way you can remove people from that service? Thanks.

    AWS Training in Bangalore | Amazon Web Services Training in Bangalore
    Amazon Web Services Training in Pune | Best AWS Training in Pune
    AWS Online Training | Online AWS Certification Course - Gangboard
    Top 110 AWS Interview Question and Answers

    ReplyDelete
  23. Good Post! Thank you so much for sharing this pretty post, it was so good to read and useful to improve my knowledge as updated one, keep blogging.
    Best Devops online Training
    Online DevOps Certification Course - Gangboard

    ReplyDelete
  24. I would assume that we use more than the eyes to gauge a person's feelings. Mouth. Body language. Even voice. You could at least have given us a face in this test.
    python Course in Pune
    python Course institute in Chennai
    python Training institute in Bangalore

    ReplyDelete
  25. This is an awesome post.Really very informative and creative contents. These concept is a good way to enhance the knowledge.I like it and help me to development very well.Thank you for this brief explanation and very nice information.Well, got a good knowledge.
    Selenium training in Chennai
    Selenium training in Bangalore
    Selenium training in Pune
    Selenium Online training

    ReplyDelete