In this c program we are going to subtract any two given integers using functions and pointers and display the output.
C program to subtract any two integers
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,sub;
clrscr();
printf("\n Enter Any Two Numbers To Subtract : ");
scanf("%d%d",&a,&b);
sub=a-b;
printf("\n Subtraction = %d",sub);
getch();
}
Output :
C program for Dev C++ to subtract two integers
#include<stdio.h>
int main()
{
int a,b,sub;
printf("\n Enter Any Two Numbers To Subtract : ");
scanf("%d%d",&a,&b);
sub=a-b;
printf("\n Subtraction = %d",sub);
getch();
return 0;
}
Output :
Subtract any two numbers using functions in c
#include<stdio.h>
#include<conio.h>
int sub(int a,int b); //function declaration
void main()
{
int result,x,y;
clrscr();
printf("\n Enter Any Two Numbers To Subtract : ");
scanf("%d%d",&x,&y);
result=sub(x,y); //calling the function
printf("\n Subtraction = %d",result);
getch();
}
int sub(int a, int b) //definition of function
{
int c;
c=a-b;
return(c);
}
C program to subtract any two given numbers using pointers
#include<stdio.h>
#include<conio.h>
void main()
{
int *p1,*p2,a,b,sub;
clrscr();
printf("\n Enter Any Two Numbers To Subtract : ");
scanf("%d%d",&a,&b);
p1=&a;
p2=&b;
sub = *p1 - *p2;
printf("\n Subtraction = %d",sub);
getch();
}
In this way we can subtract two numbers in c programming.