Professional Documents
Culture Documents
(18.10.05) MIM-SEM1-L09-21-Add - Sub - Mul - Div Using Function PDF
(18.10.05) MIM-SEM1-L09-21-Add - Sub - Mul - Div Using Function PDF
(18.10.05) MIM-SEM1-L09-21-Add - Sub - Mul - Div Using Function PDF
#include <stdio.h>
// Function Definition
void add()
{
int i,j;
printf("Enter 2 Numbers\n");
scanf("%d%d",&i,&j);
printf("The sum of %d and %d is %d.",i,j,i+j);
}
void sub()
{
int i,j;
printf("Enter 2 Numbers\n");
scanf("%d%d",&i,&j);
printf("The sum of %d and %d is %d.",i,j,i-j);
}
void mul()
{
int i,j;
printf("Enter 2 Numbers\n");
scanf("%d%d",&i,&j);
printf("The sum of %d and %d is %d.",i,j,i*j);
}
int main()
{
int i;
printf("Enter \nOption 1: Addition\nOption 2: Subtraction\nOption 3: Multiplication\n");
scanf("%d",&i);
switch(i)
{
case 1: add();break;
case 2: sub();break;
case 3: mul();break;
}
return 0;
}
P03: PROGRAM TO DO OPERATION ON TWO NUMBERS USING FUNCTIONS
#include <stdio.h>
// Function Definition
// Parameters : i,j
int add(int i, int j)
{
// Return Variable
return (i+j);
}
int main()
{
int a,b,o,r;
printf("Enter Two Numbers:\n");
scanf("%d%d",&a,&b);
case 2:
r=sub(a,b);
printf("Difference of %d and %d = %d",a,b,r);
break;
case 3:
r=mul(a,b);
printf("Multiplication of %d and %d = %d",a,b,r);
break;
case 4:
r=division(a,b);
printf("Division of %d and %d = %d",a,b,r);
break;