89 167
Assignments Done
98.2%
Successfully Done
In August 2020

# Answer to Question #40439 in C++ for Ahmed al mamari

Question #40439
Make use of switch statement. The outline of this program is given below:
/* A menu driven program */
void main
{
int choice ;
int Number;
while (1)
{
printf ( &quot;\n1. Factorial&quot; ) ;
printf ( &quot;\n2. Odd/Even&quot; ) ;
printf ( &quot;\n3. Exit&quot; ) ;\
printf(&quot;\n Enter Number&quot;);
scanf(&quot;%d&quot;,&Number);
printf ( &quot;\nYour choice? &quot; ) ;
scanf ( &quot;%d&quot;, &choice ) ;
switch ( choice )
{
case 1 :
/* logic for factorial of a Number */
break ;
case 2 :
/* logic for odd/even */
break ;
case 3 :
exit() ;
}
}
}
1
2014-03-24T12:16:12-0400
#include <stdio.h>
#include <stdbool.h>

int factorial(long long int n) {
if ( n < 0 ) {
return -1;
}
if ( n < 2 ) {
return 1;
} else {
return n * factorial(n-1);
}
}

bool even(int n) {
if ( n % 2 == 0 ) {
return true;
}
return false;
}

int main() {
int choice ;
int Number;

while (1) {
printf ( "\n1. Factorial" ) ;
printf ( "\n2. Odd/Even" ) ;
printf ( "\n3. Exit" ) ;\
printf("\nEnter Number\n");
scanf("%d",&Number);
printf ( "\nYour choice?\n" ) ;
scanf ( "%d", &choice ) ;
switch ( choice ) {
case 1 :
printf(" Factorial of the number %d is %d", Number, factorial(Number));
break ;
case 2 :
if ( even(Number) == true ) {
printf("The given number is even\n");
} else {
printf("The number is odd\n");
}
break ;
case 3 :
return 0 ;
default:
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!