1 / 4
2 / 4
3 / 4
4 / 4

Tuesday, 21 March 2023

Add, Substract,Multiply and Divide Two Integers in C Program

 

In Mathematics the formula for SUM is a+b=c.


But our machine doesn't know mathematical equations.


Here is the simple code to add Two numbers in the C program


#include<stdio.h>

int main(){
int num1=10,num2=20;
printf("Sum is : %d",num1+num2);
return 0;
}


Let's take two inputs from the user.


For that, we have to read the value given by the user to do this, and we have to use scanf.


It reads the user input and stores it in a variable.

So here is the code for user input and adding two integers.


#include<stdio.h>

int main(){
    int num1,num2;
    printf("Enter 1st Number : ");
    scanf("%d",&num1);
    printf("Enter 2nd Number : ");
    scanf("%d",&num2);
   
    printf("Sum is : %d",num1+num2);
    return 0;
}

Like the above example, we can do Subtraction (-), Multiplication (*), and  Division(/) operations by replacing the + sign with the -, *, and / symbols.


Thank you.


Try and write your query.

No comments:

Post a Comment

If you have any doubts please let me know