Written a C Program for addition, subtraction, multiplication, and division for two given numbers by the user.
Read this article till to end and understand the program's logics of arithmetic operations.
The C programs for Arithmetic Operations
1. Addition 2. Subtraction 3. Multiplication 4. Division
Program Logic : For those operations, we follow those steps for all programs
1. We write a c program for getting 2 values from the User that was only Integer.
2. Performing arithmetic operation by using that operator, And stored result in another variable. - [You can also use the Assignment operator.]
3. Final answer will display by using " printf() ".
" Read it and try its own self. "
1. Write a C program to find an Addition of two numbers
The C Program Codes for Addition, The Addition can do in Three ways.
1. Using the sum function which uses for addition.
2. Create a small code of addition as given below.
3. Direct print the answer of addition by simply writing a+b.
Here, We have written C Program to display the Addition of the given two Numbers.
" You can add more numbers by adding more variables "
#include<stdio.h> #include<math.h> int main() { //Declaration of variable int number1,number2,sum; // Get valuse for numbers by user printf("\nEnter first number = "); scanf("%d",&number1); printf("\nEnter second number = "); scanf("%d",&number2); // Addition by using SUM Function // sum=sum(number1,number2); // Addition Without Function sum=number1+number2; // Display Answer of Addition printf("Answer of Addition = %d",sum); // Direct display the answer of Addition without use other variable /* printf("Answer of Addition = %d:,number1+number2); */ return 0; }
OUTPUT :
Enter first number: 10
Enter second number: 20
Answer of Addition = 30 code-box
Now, we see a subtraction of two numbers.
2. Write a C program to find the Subtraction of two numbers.
There was the same logic used as an upper program. Here we just change the arithmetic operator ' + ' to ' - '.
#include<stdio.h> #include<math.h> int main() { //Declaration of variable int number1,number2,sub; // Get valuse for numbers by user printf("\nEnter first Digit = "); scanf("%d",&number1); printf("\nEnter second Digit = "); scanf("%d",&number2); // Subtraction sub=number1-number2; // Display Answer of Subtraction printf("Answer of Addition = %d",sub); // Direct display the answer of Subtraction without use other variable // By place '-' between number1 and number2 printf("Answer of Subtraction = %d:,number1-number2); return 0; }
OUTPUT :
Enter first number: 10
Enter second number: 20
Answer of Addition = 10 code-box
3. Write a C program to find the Multiplication of two numbers.
There was the same logic used as an upper program. Here we just change the arithmetic operator ' - ' to ' * '.
For the C language and many other languages the star symbol * used for multiplication. In a C language is also used for the pointer.
#include<stdio.h> #include<math.h> int main() { //Declaration of variable int number1,number2,multi; // Get valuse for numbers by user printf("\nEnter first Digit = "); scanf("%d",&number1); printf("\nEnter second Digit = "); scanf("%d",&number2); // Subtraction multi=number1*number2; // Display Answer of Multiplication printf("Answer of Multiplication= %d",multi); // Direct display the answer of Multiplivation without use other variable // By place '*' between number1 and number2 printf("Answer of Multiplication = %d:,number1*number2); return 0; }
OUTPUT :
Enter first number: 10
Enter second number: 20
Answer of Addition = 200 code-box
4. Write a C program to find the Division of two numbers.
There was the same logic used as an upper program. Here we just change the arithmetic operator ' * ' to ' / '.
For the C language, a single Forward slash ' / ' is for Division, and double ' // ' use for Single line comment.
#include<stdio.h> #include<math.h> int main() { //Declaration of variable int number1,number2,divi; // Get valuse for numbers by user printf("\nEnter first Digit = "); scanf("%d",&number1); printf("\nEnter second Digit = "); scanf("%d",&number2); // Subtraction divi=number1/number2; // Display Answer of Division printf("Answer of Division = %d",divi); // Direct display the answer of Division without use other variable // By place '*' between number1 and number2 printf("Answer of Division = %d:,number1/number2); return 0; }
OUTPUT :
Enter first number: 25
Enter second number: 5
Answer of Addition = 5 code-box
Those are the C program for performing Arithmetic operations. Those programs are the same we just change out the arithmetic oerators. [ Calculation symbols like +, -, *, / ]
If you have any questions or doubts regarding those codes or any other program, so just write in the comment box.
We will solve your doubts or problem.
Post a Comment