• Skip to primary navigation
  • Skip to content
  • Skip to primary sidebar
  • Home
  • How To’s
  • Lifestyle
  • Sports
  • Photography
  • Courses
  • Contact Us
  • SnazzyMedia Team

Snazzy Media

your world amplified!

  • Disclaimer
  • Privacy
  • Contact Us

September 30, 2016

Multiple operations; C# Exercises and Solutions

1.7 – Multiple operations with same numbers

Question


Write a program to accept two numbers from user and perform Addition, Subtraction, Multiplication and Division(Remainder and Quotient) and display in format given below

for ex.  enter first number = 13

enter second number = 4

13 + 4 = 17

13 – 4 = 9

13 * 4 = 52

13 / 4 = 3

13 % 4 = 1


Solution


class SameNumbersMultipleOperations
    {
        static void Main(string[] args)
        {
            int a, b, c, d, e, f, g;                  //initialization
            Console.Write(“Enter first number : “);
            a = Convert.ToInt16(Console.ReadLine());
            Console.Write(“Enter second number : “);
            b = Convert.ToInt16(Console.ReadLine());
            c = a + b;                      //calculation for addition     
            d = a – b;                      //calculation for subtraction
            e = a * b;                      //calculation for multiplication
            f = a / b;                      //calculation for quotient
            g = a % b;                      //calculation for remainder
            Console.WriteLine(“{0} + {1} = {2}”, a, b, c);
            Console.WriteLine(“{0} – {1} = {2}”, a, b, d);
            Console.WriteLine(“{0} * {1} = {2}”, a, b, e);
            Console.WriteLine(“{0} / {1} = {2}”, a, b, f);
            Console.WriteLine(“{0} % {1} = {2}”, a, b, g);
        }
    }

 Previous                                                Home                                                   Next


Output

7


 

Spread some love:

  • Twitter
  • Facebook
  • WhatsApp
  • Pocket
  • Reddit
  • Pinterest
  • LinkedIn

Related

Filed Under: Uncategorized Tagged With: .NET, C#, Programming

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published.

Primary Sidebar

Recent Posts

  • Aegon Life Insurance re-announces its Unique and beneficial “iTerm” online Protection plan
  • Vivo V5 : 20 MP Front Camera for a Perfect Selfie
  • A Flying Jatt : Our Desi SuperHero with some Desi Moves
  • Honor launches Honor 8, Honor 8 Smart and Holly 3 in India
  • How to Remove a Bubble Gum from your Shoe?

Recent Comments

  • kolly on Samsung launches Galaxy J7 Prime and J5 Prime in India
  • Jay on GOQii Band 2.0 : The best in class fitness band with USB charging for the first time!

Categories

  • Android Apps
  • C#
  • Courses
  • Featured
  • Fitness
  • Gadgets
  • Health & Fitness
  • How To
  • Lifestyle
  • Science
  • Space
  • Sports
  • Travel
  • Uncategorized
  • Video

Meta

  • Log in
  • Entries RSS
  • Comments RSS
  • WordPress.org

Copyright© 2021 · by Shay Bocks