Write a single C program to perform the following operations. Read the choice where, if the choice is 1 Multiplication should be performed, if the choice is 2 Area of Circle should be executed, if the choice is 3 them it has to execute the function of checking number is even or odd, if the choice is 4 then it has to find the factorial of a number and if the choice is 5 then execute the function smallest of 3 numbers
#include <stdio.h>
int multiplication(int x,int y){
return (x*y);
}
double area(double r){
return(3.142*r*r);
}
void odd_even(int x){
if (x%2==0)
printf("%d is even",x);
else
printf("%d is odd",x);
}
int factorial(int n){
int i;
unsigned long long fact = 1;
if (n < 0)
printf("Error!");
else {
for (i = 1; i <= n; ++i) {
fact *= i;
}
printf("Factorial of %d = %llu", n, fact);
}
}
int smallest(int num1,int num2,int num3){
if(num1 < num2 && num1 < num3)
{
printf("%d is smallest",num1);
}
else if(num2 < num3)
{
printf("%d is smallest",num2);
}
else
{
printf("%d is smallest",num3);
}
}
int main()
{
int ch;
printf("1.multiplication\n2.Area\n3.Odd or even\n4.factorial\nSmallest\n");
printf("\nEnter your choice:");
scanf("%d",&ch);
switch(ch){
case 1:
multiplication(4,6);
break;
case 2:
area(7);
break;
case 3:
odd_even(10);
break;
case 4:
factorial(5);
break;
case 5:
smallest(34,23,56);
break;
}
return 0;
}
Comments
Leave a comment