Hello Coders,

In this post we are going to learn about the Arithmetic Operations in different programming languages. Such as C++, Java and Python. Let us first learn about the Arithmetic operators, what is arithmetic operators ?

Arithmetic operators are simple mathematical operators such as +, -, x, ÷ . The operations which are done using these operators are called as Arithmetic  Operations. For '+' it is Addition, for '-' it is Subtraction, for 'x' it is multiplication and for '÷' it is division.

In programming languages, the symbols for addition and subtraction are same as in mathematics but for multiplication it is ' * ' (asterisk) and for division it is ' / ' (forward slash).

Given below is the code for three programming languages, in that code bits some comments are added please read it carefully to understand the syntax for the languages.
We will be learning this program in four different programming languages C, C++, Java and Python.
 
So let's get started.

C


 #include <stdio.h>
 int main()
 {   
     //Declaring variables
     int num1, num2; 
     float output;

     //Printing the statement for first input
     printf("Enter the value of first number \n");

     //Taking first input from user
     scanf("%d", &num1);

     //Printing the statement for second input
     printf("Enter the value of second number \n");

     //Taking second input user
     scanf("%d", &num2);

     //Calculating the Addition of two numbers
     output = num1 + num2;

     //Printing the output of addition
     printf("output for addition of two number is %f \n", output);

     //Calculating the subtraction of two numbers
     output = num1 - num2;

     //Printing the output of subtraction
     printf("output for subtraction of two numbers is %f \n",output);

     //Calculating the multiplication of two numbers
     output = num1 * num2;

     //Printing the output of multiplication
     printf("output for multiplication of two numbers is %f \n",output);

     //Calculating the diivision of two numbers
     output = num1 / num2;

     //Printing the output of division
     printf("output for division of two numbers is %f \n",output);
     return 0;
 }
          



Output for C



C++


          
//This is a Arithmetic Calculation Program in C++

//Including Header files
#include <iostream>
using namespace std;

//Main function of program, starting point
 int main()
 {
    //Initializing the variables for operations
    int first_num, second_num, result;

    //Printing a statement for user input
    cout << "\nEnter the two number for Operations" << endl;

    //Taking user input in the variables
    cin >> first_num >> second_num;

    //calculating  and Showing result for Addition
    result = first_num + second_num;
    cout << "The Additoin is = " << result << endl;

    //calculating  and Showing result for Subtraction
    result = first_num - second_num;
    cout << "The Subtraction is = " << result << endl;

    //calculating  and Showing result for Multiplication
    result = first_num * second_num;
    cout << "The Multiplication is = " << result << endl;

    //calculating  and Showing result for Division
    result = first_num / second_num;
    cout << "The Division is = " << result << endl;

    return 0;
 }
          



Output for C++



Java


 package com.company;

 // Import java util package this will help to use Scanner class
 import java.util.*;

 //Class Main
 //Starting point of program
 public class Main
 {

    //This is the main Function
    public static void main(String[] args)
    {

       Scanner sc = new Scanner (System.in);

       System.out.println("**Program for Arithmetic Operations**\n");

       //Printing a Statement to take user input
       System.out.println("Enter two numbers for Arithmetic operations\n");

       //Initializing the variables as integer datatype
       int first_num = sc.nextInt();
       int second_num = sc.nextInt();

       //Initializing the result for Arithmetic operations
       int result_add = first_num + second_num;
       int result_sub = first_num - second_num;
       int result_mult = first_num * second_num;
       int result_div = first_num / second_num;

       //Printing the result of all Arithmetic operations
       System.out.println("The Addition is = "+ result_add);
       System.out.println("The Subtraction is = "+ result_sub);
       System.out.println("The Multiplication is = "+ result_mult);
       System.out.println("The Division is = "+ result_div);

    }
 }
    


Output for JAVA



Python


 # This is the Arithmetic Operation Programs in Python
 print("\n **** Arithmetic Operation Program ****\n")

 # Printing a Statement for user input for Operations
 print("Enter the two number for Arithmetic operations\n")

 # Taking input from user
 first_num = int(input(""))
 second_num = int(input(""))

 # Calculating result of all Arithmetic Oprations

 result_add = first_num+second_num
 result_sub = first_num-second_num
 result_mult = first_num*second_num
 result_div = first_num/second_num

 # Showing result of all Arithmetic Oprations
 print("The Addition is = ",result_add)
 print("The Subtraction is =",result_sub)
 print("The Multiplication is =",result_mult)
 print("The Division is =",result_div)



Output for PYTHON





//ENJOY CODING\\

Post a Comment

FOR ANY DOUBTS AND ERRORS FEEL FREE TO ASK. YOUR DOUBTS WILL BE ADDRESSED ASAP

Previous Post Next Post