Question

In: Computer Science

compute and print factorial if it is equal to 6, not equal to 6, and square...

compute and print factorial if it is equal to 6,

not equal to 6,

and square of the factorial, if the input is equal to 6 ..... C programming

Solutions

Expert Solution

#include <stdio.h>

int factorial(int a); //function prototype to calculate factorial

int main(int argc, char *argv[]) {

int a,b;
printf("Enter input:\n");
scanf("%d",&a); //stores the input
b=factorial(a); //calculate factorial of input
  
printf("Factorial of %d is %d\n",a,b); //display factorial
if(a==6){
   printf("Square of factorial of %d is %d\n",a,b*b); //if input is 6 then display square of factorial also
}
  
return 0;


}

//function to calculate factorial
int factorial(int a){
   if(a==0){
       return 1;
   }else{
       return a*factorial(a-1);
   }
}


Related Solutions

In python import numpy as np Given the array b = np.arange(-6, 4) compute and print...
In python import numpy as np Given the array b = np.arange(-6, 4) compute and print 1.) The array formed by \(bi^2 - 1\), where the \(bi\) are the elements of the array b. 2.) The array formed by multiplying b with the scalar 100. 3.)The array formed by 2.0 b i in reverse order. (Note: the base 2.0 must be a floating point number; for integer values a ValueError: Integers to negative integer powers are not allowed. is raised.)...
Replace <missing value> and <missing code> with your answers. Your code should compute the factorial of...
Replace <missing value> and <missing code> with your answers. Your code should compute the factorial of n. For example, if n = 5, your code should compute the following 5 * 4 * 3 * 2 * 1 (which is 120). public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int n = scanner.nextInt(); int factorial = <missing value>; <missing code> System.out.println("factorial = " + factorial);
Compute the mean square error using equation s2 = MSE =
Consider the data. xi 1 2 3 4 5 yi 4 8 6 12 14 (a) Compute the mean square error using equation  s2 = MSE = SSE n − 2  . (Round your answer to two decimal places.) (b) Compute the standard error of the estimate using equation s = MSE = SSE n − 2  . (Round your answer to three decimal places.) (c) Compute the estimated standard deviation of b1 using equation sb1 = s Σ(xi −...
(a) Compute the mean square error using equation s2 = MSE =
Consider the data. xi 1 2 3 4 5 yi 4 6 5 12 13 (a) Compute the mean square error using equation s2 = MSE = SSE n − 2  . (Round your answer to two decimal places.) (b) Compute the standard error of the estimate using equation s =MSE= SSE n − 2 =  . (Round your answer to three decimal places.) (c) Compute the estimated standard deviation of b1 using equation sb1 = s Σ(xi − x)2...
Please explain why. Note that Latin square designs are equivalent to specific fractional factorial designs (e.g.,...
Please explain why. Note that Latin square designs are equivalent to specific fractional factorial designs (e.g., the 4x4 Latin square design is equivalent to a 43-1fractional factorial design). Please explain why.
Two diagonals of a rhombus are equal. Is it a square? Justify your answer.
Two diagonals of a rhombus are equal. Is it a square? Justify your answer.
What is Factorial Experiment Types of Factorial Experiment Uses of Factorial Experiment in research Example of...
What is Factorial Experiment Types of Factorial Experiment Uses of Factorial Experiment in research Example of Each types of Factorial Experiment Conclusion Reference
Statement: For a given integer N, print all the squares of positive integers where the square...
Statement: For a given integer N, print all the squares of positive integers where the square is less than or equal to N, in ascending order. Programming Tasks: Prompt the user to input the value of N Output to the screen all squares of positive integers <= N Tests: Item Test 1 Test 2 Test 3 Inputs: 50 9 100 Outputs: 1 4 9 16 25 36 49 1 4 9 1 4 9 16 25 36 49 64 81...
Write a program that reads two square Matrices of size 2 *2 and calculate and print...
Write a program that reads two square Matrices of size 2 *2 and calculate and print the sum of them. Also, the signed value of the matrices are input by the user Note: 1) Use CamelCase for variables names 2) Write Comments such as your name, the class, description of the program, and description of your logic. 4) Use sematic names for your variables 5) Your program should be C program not C++.
The standard deviation is equal to the square root of the average squared deviations about the...
The standard deviation is equal to the square root of the average squared deviations about the mean. More succintly, it is equal to the square root of the variance. So one way to calculate the standard deviation of a frequency distribution is to calculate the variance. Complete the table below as the first step in calculating the variance: (10 points) X f X−x (X−x)2 96 1 94 1 92 1 87 1 85 1 84 1 83 1 82 1...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT