Wednesday, 19 October 2011

add,sub,mul,div using finction


#include<stdio.h>
#include<conio.h>
#include<process.h>
add(int,int);
sub(int,int);
mul(int,int);
div(int,int);
main()
{
int a,b,c;
int choice;
clrscr();
printf("enter the two number");
scanf("%d %d",&a,&b);
do
{
printf("\n1.ADD 2.SUB 3.MUL 4.DIV 5.Exit");
printf("\nenter ur choice");
scanf("%d",&choice);
switch(choice)
{
case 1:
c=add(a,b);
printf("value of c is %d\n",c);
break;

case 2:
c=sub(a,b);
printf("value of c is %d\n",c);
break;

case 3:
c=mul(a,b);
printf("value of c is %d\n",c);
break;

case 4:
c=div(a,b);
printf("value of c is %d",c);
break;
}
}while(choice!=5);
getch();
return 0;
}   //end of main

add(int x,int y)
{
int z;
z=x+y;
return (z);
}

sub(int x,int y)
{
int z;
z=x-y;
return (z);
}

mul(int x,int y)
{
int z;
z=x*y;
return (z);
}

div(int x,int y)
{
int z;
z=x/y;
return(z);
}

No comments:

Post a Comment