programs on function example
#include<stdio.h>
#include <conio.h>
int sum(int, int);
void diff();
int prod();
void div(int, int);
void main()
{
int a,b,res;
clrscr();
printf("Enter 2 numbers:");
scanf("%d%d", &a,&b);
res=sum(a,b);
printf("nSum is %dn",res);
diff();
res=prod();
printf("nThe product is %d",res);
div(a,b);
getch();
}
int sum(int x, int y)
{
return(x+y);
}
void diff()
{
int a,b;
printf("nnEnter 2 numbers:");
scanf("%d%d",&a,&b);
printf("Difference id %d",a-b);
}
int prod()
{
int a,b;
printf("nnEnter two numbers:");
scanf("%d%d",&a,&b);
return(a*b);
}
void div(int x, int y)
{
printf("nnDivision of %d and %d results in %f",x,y,(float) x/y);
}
#include <stdio.h>
#include <conio.h>
int hcf(int,int);
void main()
{
int a,b,h;
clrscr();
printf("Enter two numbers:");
scanf("%d%d",&a,&b);
h=hcf(a,b);
printf("nnHCF of %d and %d is %d.",a,b,h);
getch();
}
int hcf(int x, int y)
{
int rem;
rem=x%y;
if(x<y)
return(hcf(y,x));
else if(rem==0)
return(y);
else
return(hcf(y,rem));
}
