Write a program to addition, substraction, multiplication, division, modulas division of two numbers using static variable in C Programming Language and also implement it in PHP

Write a program to addition, substraction, multiplication, division, modulas division of two numbers using static variable in C Programming Language and also implement it in PHP.

Using C Programming Language

STEP 1: Before starting just let me tell you where you can code C programming and runs the programming easily is Programiz C Online Compiler. Just go to google and type C Compiler and open the first link "Online C Compiler - Programiz".

STEP 2: Once the Programiz C Online Compiler window gets open here you can type your C programming code and after writing the code here you can run the program code and you will be able to see the output.


STEP 3: In my below C programming code I have taken two variable names and its value and variable type. So, here my variable type is integer (int) and I have taken two variable name i and j whose value is i=100 and j=50. After that I have print the value by using printf of i and j in addition as i+j, subtraction as i-j, multiplication as i*j, division as i/j and modulas division as i%j and here I have used return 0; as because if int main is true then it returns the value and it returns value 0 so as here I have used int main() so I have taken return 0;.

C CODE:

#include<stdio.h>
int main()
{
    int i=100,j=50;
    printf("The add. is = %d",i+j);
    printf("\nThe sub. is = %d",i-j);
    printf("\nThe mul. is = %d",i*j);
    printf("\nThe div. is = %d",i/j);
    printf("\nThe mod. div. is = %d",i%j);
    return 0;
}

 C OUTPUT:

The add. is = 150
The sub. is = 50
The mul. is = 5000
The div. is = 2
The mod. div. is = 0

=== Code Execution Successful ===--


Using PHP

NOTE: We need to write all the PHP codes by starting the "Apache" Module in XAMPP. 

STEP 1: Before starting using PHP just let me tell you that to code in PHP using sublime text you need to first download XAMPP software from google. Just you need to go to google and type "XAMPP download softonic 8.2.12" and then you need to click on the 3rd link "Download XAMPP - free-latest version-Softonic" and then once the 3rd link gets open you need to scroll down and then you need to click on "Free Download for PC" and once you click on "Free Download for PC" it will start downloading and then once it is downloaded just click on "Yes" option and then keep the preferred language "English" default and click on "Next", and again click on "Next" and then it will get installed.






STEP 2: The XAMPP software looks like below where we have 5 Modules "Apache", "MySQL", "FileZilla", "Mercury" and "Tomcat". But here in PHP we will use "Apache" Module in XAMPP software and also we need to start and stop the "Apache" Module while writing code in PHP and then we need to create folder In C Drive by right click new -> folder with folder name inside XAMPP -> htdocs and then we need to open the folder which we have created inside XAMPP -> htdocs in sublime text and then we need to create new folder under that php folder in sublime text.








STEP 3: In PHP we need to print the output by using echo where in C we were using printf. And the syntax of php is "<?php -> enter -> ?>" and here in PHP before declaring the variable we need to declare each variable using dollar symbol ($) in each and every php code.

STEP 4: Here in PHP, I have written the syntax "<?php -> enter -> ?>" and within syntax I have declared two variables with dollar symbol ($) one is $m=80 and another is $n=50 and then I have taken echo to print the output of addition as echo "The add. is ".$m + $n,"<br>";, subtraction as echo "The sub. is ".$m - $n,"<br>";, multiplication as echo "The mul. is ".$m * $n,"<br>";, division as echo "The div. is ".$m / $n,"<br>"; and modulas division as echo "The mod. is ".$m % $n;. Here I have used the dot symbol (.) to concatenate the strings and <br> symbol is used for going into the next line.

STEP 5: Then we need to right click on PHP code and click on "Copy File Path" and then we need to paste the path in google "C:\xampp\htdocs\Ayan.php\add,sub,mul,div,mod div.php" and from here we need to remove  upto htdocs path file:///C:/xampp/htdocs and paste here "127.0.0.1" or "localhost" before Ayan.php\add,sub,mul,div,mod div.php.





PHP CODE:

<?php
$m=80;$n=50;
echo "The add. is ".$m + $n,"<br>";
echo "The sub. is ".$m - $n,"<br>";
echo "The mul. is ".$m * $n,"<br>";
echo "The div. is ".$m / $n,"<br>";
echo "The mod. is ".$m % $n;
?>


PHP OUTPUT:

The add. is 130
The sub. is 30
The mul. is 4000
The div. is 1.6
The mod. is 30


















 








   



   

Comments