Protec Computer Academy (An ISO 9001:2015 Certified Institute, Powered by E-Max Education, Branch Code EMAX/EK-80503, Registered by government of India.) is a best IT training center in Siwan with 100% Job placement assistance. Where you can learn Programming, WebDesigning, Hardware|Networking, Blogging, WordPress, Digitial marketing, English Speaking, And many more...| All certificates are valid in Government Jobs as well as in Private Companies. *** At Tara Market, Beside Vishal Mega Mart - Siwan*** +917541905230, Email- ahmad.irshad781@gmail.com *** Follow us on | | @welcome2protec

Thursday, June 4, 2020

Program to perform all arithmatic operations in C



C Program to perform all arithmatic operations:
By Ahmad Irshad | Programming Exercises and Solutions > All arithmatic operations

How to perform all arithmatic operations (like addtion, subtraction, multiplication division etc.) between two numbers in C programming. 

In previous exercise, we have learned how to write C program to add two numbers input given by a user.

Required knowledge for this exercise is: 

Program to perform all arithmetic operations: 

  1. /* C program to perform all arithmetic operations */ #include <stdio.h> int main() { int num1, num2; int sum, sub, mult, mod; float div; /* * Input two numbers from user */ printf("Enter any two numbers: "); scanf("%d%d", &num1, &num2); /* * Perform all arithmetic operations */ sum = num1 + num2; sub = num1 - num2; mult = num1 * num2; div = (float)num1 / num2; mod = num1 % num2;
  2. /* * Print result of all arithmetic operations */ printf("SUM = %d\n", sum); printf("DIFFERENCE = %d\n", sub); printf("PRODUCT = %d\n", mult); printf("QUOTIENT = %f\n", div); printf("MODULUS = %d", mod); return 0; }

Note: In statements div = (float) num1 / num2; It has been typecasted num1 to float before the division to avoid integer division. 

Visit to learn more about typecasting.

Output:

  1. Enter any two numbers: 100, 20
  2. Sum = 120
  3. Difference =  80
  4. Product = 2000
  5. Quotient = 5.000000
  6. Modulus = 0







Next Topic to be updated soon..>>



Protec Computer Academy (An ISO 9001:2015 Certified Institute, Powered by E-Max Education, Branch Code EMAX/EK-80503, Registered by government of India.) is a best IT training center in Siwan with 100% Job placement assistance. Where you can learn Programming, WebDesigning, Hardware|Networking, Blogging, WordPress, Digitial marketing, English Speaking, And many more...| All certificates are valid in Government Jobs as well as in Private Companies. *** At Tara Market, Beside Vishal Mega Mart - Siwan*** +966532621401, Email- ahmad.irshad781@gmail.com *** Follow us on | | @welcome2protec

Help others by sharing this page.

Ahmad Irshad

Author & Editor

I love blogging, teaching, learning computer science and sharing it to others. I've written and develped this site so that students may learn computer science related tutorials eaisly. MCA / MCITP

0 Comments:

Post a Comment

Please don't enter any spam link in the comment box.


Protec Computer Academy (An ISO 9001:2015 Certified Institute, Powered by E-Max Education, Branch Code EMAX/EK-80503, Registered by government of India.) is a best IT training center in Siwan with 100% Job placement assistance. Where you can learn Programming, WebDesigning, Hardware|Networking, Blogging, WordPress, Digitial marketing, English Speaking, And many more...| All certificates are valid in Government Jobs as well as in Private Companies. *** At Tara Market, Beside Vishal Mega Mart - Siwan*** +966532621401, Email- ahmad.irshad781@gmail.com *** Follow us on | | @welcome2protec
Protec Protec Protec Protec Protec Protec Protec Protec Protec Protec Protec Protec Protec Protec Protec Protec
Contact Us