Â
In this we are going to see the Functions that have Arguments and Returns a Value, in this program we will perform Arithmetic Operations using C programming language.
// Program to perform Arithmetic Operations using functions - Type 4
#include <stdio.h>
int add(int x, int y)
{
return x + y;
}
int sub(int a, int b)
{
return a - b;
}
float mul(float x, float y)
{
return x * y;
}
float div(float x, float y)
{
return x / y;
}
void main()
{
int operation;
int a, b;
float num1, num2;
printf("-----Select the Operation------\n");
printf("1. Addition\n2. Subtraction\n3. Multiplication\n4. Division\n");
printf("Enter the corresponding number of Operation: ");
scanf("%d", &operation);
switch (operation)
{
case 1:
printf("Enter 2 numbers: \n");
scanf("%d\n%d", &a, &b);
printf("Addition is: %d", add(a, b));
break;
case 2:
printf("Enter 2 numbers: \n");
scanf("%d\n%d", &a, &b);
printf("Subtraction is: %d", sub(a, b));
break;
case 3:
printf("Enter 2 numbers: \n");
scanf("%f\n%f", &num1, &num2);
printf("Multiplication is: %f", mul(num1, num2));
break;
case 4:
printf("Enter 2 numbers: \n");
scanf("%f\n%f", &num1, &num2);
printf("Division is: %f", div(num1, num2));
break;
default:
printf("Wrong input");
}
}
#ENJOY CODING
Post a Comment
FOR ANY DOUBTS AND ERRORS FEEL FREE TO ASK. YOUR DOUBTS WILL BE ADDRESSED ASAP