Â
In this we are going to see the Functions that have Arguments but no Return Value, in this program we will perform Arithmetic Operations using C programming language.
// Program to perform Arithmetic Operations using functions - Type 2
#include <stdio.h>
void add(int x, int y)
{
printf("Additon is: %d", x + y);
}
void sub(int x, int y)
{
printf("Subtraction is: %d", x - y);
}
void mul(float x, float y)
{
printf("Multiplication is: %f", x * y);
}
void div(float x, float y)
{
printf("Division is: %f", 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 two numbers:\n");
scanf("%d\n %d", &a, &b);
add(a, b);
break;
case 2:
printf("Enter two numbers: \n");
scanf("%d\n %d", &a, &b);
sub(a, b);
break;
case 3:
printf("Enter two numbers: \n");
scanf("%f\n %f", &num1, &num2);
mul(num1, num2);
break;
case 4:
printf("Enter two numbers: \n");
scanf("%f\n %f", &num1, &num2);
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