Answer to Question #291085 in C for Nikhil

Question #291085

Given the function signatures


Multiplication- int multiplication(int a,int b)


Area of the circle- float circle_area(int radius)


Check if the number is even or odd- void iseven(int number)


Find factorial- int fact(int n)


Smallest of 3 number- int smallest(int a,int b, int c)



Write a single C program to perform the following operations. Read the choice where , if choice is 1 Multiplication should be performed, if choice is 2 Area of Circle should be executed, if 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
2022-01-27T09:27:12-0500
#include<conio.h>
#include<stdio.h>
#include<stdlib.h>
#include <iostream>
using namespace std;


/*
	Given the function signatures
	Multiplication- int multiplication(int a,int b)
	Area of the circle- float circle_area(int radius)
	Check if the number is even or odd- void iseven(int number)
	Find factorial- int fact(int n)
	smallest of 3 number- int smallest(int a,int b, int c)
	Write a single C program to perform the following operations. Read the choice where , if choice is 1 Multiplication should be performed, if choice is 2 Area of Circle should be executed, if 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
*/




#define PI 3.1457
void multiplication(int a, int b)
{
	cout<<"\n\tMultiplication: "<<a<<" * "<<b<<" = "<<a*b;
}


float circle_area(int radius)
{
	float area;
	area = PI * radius * radius;
	return(area);
}




void iseven(int number)
{
	if(number%2==0) cout<<"\n\tThe number "<<number<<" is even.;
}


void isodd(int number)
{
	if(number%2==1) cout<<"\n\tThe number "<<number<<" is even.;
}


int fact(int n) 
{
    if (n>=1)
        return n*factorial(n-1);
    else
        return 1;
}


int smallest(int a, int b, int c)
{
	int min;
	min=a;
	if(min>=a) min = a;
	if(min>=b) min = b;
	if(min>=c) min = c;
	return(min);
}


int main()
{
	int r,Choice=1,a,b;
	float rad;
	
	while(Choice)
	{
		cout<<"\n\tPress-1 for Multiplication";
		cout<<"\n\tPress-2 for Even Check";
		cout<<"\n\tPress-3 for Odd Check";
		cout<<"\n\tPress-4 for circle area";
		cout<<"\n\tPress-5 for factorial";
		cout<<"\n\tPress-6 for smallest number";
		cout<<"\n\tPress-0 to QUIT.";
		Choice = -1;
		while(Choice<0 || Choice>6)
		{
			cout<<"\n\tEnter Choice (0 to 6): "; cin>>Choice;
		}
	}
	if(Choice==1)
	{
		cout<<"\n\tEnter a: "; cin>>a;
		cout<<"\n\tEnter b: "; cin>>b;
		multiplication(a,b);	
	}
	if(Choice==2)
	{
		cout<<"\n\tEnter a: "; cin>>a;
		iseven(a);
	}
	if(Choice==3)
	{
		cout<<"\n\tEnter a: "; cin>>a;
		isodd(a);
	}
	if(Choice==4)
	{
		cout<<"\n\tEnter Radius: "; cin>>rad;
		a = circle_area(rad);
	}
	if(Choice==5)
	{
		cout<<"\n\tEnter a: "; cin>>a;
		b = fact(a);
	}
	if(Choice==6)
	{
		cout<<"\n\tEnter a: "; cin>>a;
		cout<<"\n\tEnter b: "; cin>>b;
		cout<<"\n\tEnter c: "; cin>>c;
		r = smallest(a,b,c);
	}
	if(Choice==0) exit(0);
	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