• Post author:
  • Reading time:1 mins read
  • Post category:C Programs

Subtract Two Integers Entered by the User in C Programming

//Write a program to subtract two integer in C?
#include<stdio.h>
int main()
{
  int result,var1,var2;
  printf("Enter the values for var1 and var2 \n");
  scanf("%d %d",&var1,&var2);
  result=var1-var2;
  printf("The result is %d \n",result);
  return 0;
}

Output

C program to subtract two integers

Code Explanation

First, declare two integer variables to store the user inputted values. Then using printf() function print “Enter the values for var1 and var2”. After that read the input values entered by the user using scanf(). These 2 values are stored in var1 and var2 respectively. Those two values are subtracted using the ‘-‘ operator. The result will be stored in variable result. This result will be displayed on the console using print().