Answer to Question #213445 in C for ABHINEET GAUR

Question #213445

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


1
Expert's answer
2021-07-05T01:07:10-0400


#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS