0% found this document useful (0 votes)
51 views3 pages

(18.10.05) MIM-SEM1-L09-21-Add - Sub - Mul - Div Using Function PDF

This C program defines functions to perform addition, subtraction, and multiplication on two input numbers. The main function prompts the user to enter two numbers and an operation to perform. It then calls the corresponding function to calculate the result and print it out. The functions are defined to either take in the numbers as parameters and return the result, or prompt for input and print output directly.

Uploaded by

Saurabh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
51 views3 pages

(18.10.05) MIM-SEM1-L09-21-Add - Sub - Mul - Div Using Function PDF

This C program defines functions to perform addition, subtraction, and multiplication on two input numbers. The main function prompts the user to enter two numbers and an operation to perform. It then calls the corresponding function to calculate the result and print it out. The functions are defined to either take in the numbers as parameters and return the result, or prompt for input and print output directly.

Uploaded by

Saurabh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

P02: PROGRAM TO PRINT SUM OF TWO FUNCTIONS USING FUNCTIONS

#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 sub(int i, int j)


{
return (i-j);
}

int mul(int i, int j)


{
return (i*j);
}

int division(int i, int j)


{
return (i/j);
}

int main()
{
int a,b,o,r;
printf("Enter Two Numbers:\n");
scanf("%d%d",&a,&b);

printf("Enter \nOption 1: Addition\nOption 2: Subtraction\nOption 3: Multiplication\nOption 4:


Division\n");
scanf("%d",&o);
switch(o)
{
case 1:
r=add(a,b);
printf("Sum of %d and %d = %d",a,b,r);
break;

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;

default: printf("Invalid Option.");


}
return 0;
}

You might also like