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

35 comments:

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

    Mobile Application Development and Testing Training

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

    ReplyDelete
  3. 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
  4. How to add two roman numerals which will show result in roman numerals only.

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

    ReplyDelete
  6. 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


  7. 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
  8. 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
  9. 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
  10. 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
  11. 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
  12. 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
  13. how will we perform addition of two numbers entering number without user in c#???
    Please Help me !

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

    ReplyDelete
  15. 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
  16. 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
  17. 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
  18. 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
  19. Attend The Python training in bangalore From ExcelR. Practical Python training in bangalore Sessions With Assured Placement Support From Experienced Faculty. ExcelR Offers The Python training in bangalore.
    python training in bangalore

    ReplyDelete

  20. My name is Leah Brown, I'm a happy woman today? I told myself that any loan lender that could change my life and that of my family after having been scammed separately by these online loan lenders, I will refer to anyone who is looking for loan for them. It gave me and my family happiness, although at first I had a hard time trusting him because of my experiences with past loan lenders, I needed a loan of $300,000.00 to start my life everywhere as single mother with 2 children, I met this honest and God fearing online loan lender Gain Credit Loan who helped me with a $300,000.00 loan, working with a loan company Good reputation. If you are in need of a loan and you are 100% sure of paying the loan please contact (gaincreditloan1@gmail.com)

    ReplyDelete
  21. This is a smart blog. I mean it. You have so much knowledge amazon web services training in Bangalore about this issue, and so much passion. You also know how to make people rally behind it, obviously from the responses.

    ReplyDelete

  22. I am looking for and I love to post a comment Python classes in punethat "The content of your post is awesome" Great work!

    ReplyDelete
  23. Really very happy to say, your post is very interesting to read. I never stop myself to say something about it. You’re doing a great job. Keep it up…

    Upgrade your career Learn Oracle Training from industry experts gets complete hands on Training, Interview preparation, and Job Assistance at Softgen Infotech.

    ReplyDelete