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