Question

In: Computer Science

Write a C program that evaluates the factorials from 1 to 5. Print results in a...

Write a C program that evaluates the factorials from 1 to 5. Print results in a tabular format.

Solutions

Expert Solution

CODE:

#include <stdio.h>

int main()
{
int fact=1;
printf("i |\t Factorial\n");
printf("----|--------------\n");
for(int i=1;i<=5;i++)
{
switch(i){
case 1: fact=fact*i;
printf("%d |\t %d\n",i,fact);
break;

case 2: fact=fact*i;
printf("%d |\t %d\n",i,fact);
break;

case 3: fact=fact*i;
printf("%d |\t %d\n",i,fact);
break;

case 4: fact=fact*i;
printf("%d |\t %d\n",i,fact);
break;

case 5: fact=fact*i;
printf("%d |\t %d\n",i,fact);
break;

default:break;
}
}

return 0;
}

SCREENSHOT AND EXPLANATION:

OUTPUT:


Related Solutions

i have this problem write an application that evaluates the factorials of the integeres from 1...
i have this problem write an application that evaluates the factorials of the integeres from 1 to 5 . i have this ! control.WriteLine( "n\tn!;n"); for (in number=1; number <=5; number ++); { int factorail=1: for (int 1=1; i<=number;1++); factorial *=1: Console.Writeline("{0}\t{1}".number,factorial); output n n! 1 1 2 2 3 6 4 24 5 120 I understand how the first row is printed.   the first 1 in because the intfactorial is 1 the #2 if printed becasue in number =1;...
(C++) Write a program that reads a list of integers from the keyboard and print out...
(C++) Write a program that reads a list of integers from the keyboard and print out the smallest number entered. For example, if user enters 0 3 -2 5 8 1, it should print out -2. The reading stops when 999 is entered.
: In this assignment you will write a C++ program that evaluates an arithmetic expression (represented...
: In this assignment you will write a C++ program that evaluates an arithmetic expression (represented with an infix notation), then outputs this expression in prefix form and also outputs the result of the calculation. The program will first convert the input infix expression to a prefix expression (using the Stack ADT) and then calculate the result (again, using the Stack ADT). The details are provided in the following sections.
C++ Write a whole program to read 50 salaries from the file “Salaries.txt” and print them...
C++ Write a whole program to read 50 salaries from the file “Salaries.txt” and print them on the screen (each value on a separate line), you have to also save the grades (each value on a separate line) into another file “SalariesWithBonus.txt” after you add a bonus of two percent to each salary (example For the salary 100000 a bonus of 2000 will be added as 100000 X 0.02 = 2000). Your code should check whether the file “Salaries.txt” opened...
ONLY IN C LANGUAGE Write a C program to print all the unique elements of an...
ONLY IN C LANGUAGE Write a C program to print all the unique elements of an array. Print all unique elements of an array Enter the number of elements to be stored in the array: 4 Input 4 elements in the arrangement: element [0]: 3 element [1]: 2 element [2]: 2 element [3]: 5 Expected output: The only items found in the array are: 3 5
C++ OOP •Write a program that evaluates a postfix expression (assume it’s valid) such as 6...
C++ OOP •Write a program that evaluates a postfix expression (assume it’s valid) such as 6 2 + 5 * 8 4 / - •The program should read a postfix expression consisting of digits and operators into a string. •The algorithm is as follows: 1.While you have not reached the end of the string, read the expression from left to right. –If the current character is a digit, Push its integer value onto the stack (the integer value of a...
Using C++ 1) Write a program that repeatedly evaluates a n-th order polynomial p(x) = a0...
Using C++ 1) Write a program that repeatedly evaluates a n-th order polynomial p(x) = a0 + a1*x + a2*x^2 + ... + an*x^n where n <= 10 The program inputs n, ai, and x from the keyboard and then prints out the corresponding value of p to the screen. The program continues to input new values of n, ai, x and evaluates p until a negative value for n is input, at which point the program stops.
USING C++ 1) Write a program that repeatedly evaluates a n-th order polynomial p(x) = a0...
USING C++ 1) Write a program that repeatedly evaluates a n-th order polynomial p(x) = a0 + a1*x + a2*x^2 + ... + an*x^n where n <= 10 The program inputs n, ai, and x from the keyboard and then prints out the corresponding value of p to the screen. The program continues to input new values of n, ai, x and evaluates p until a negative value for n is input, at which point the program stops. 2)Write a...
Write a complete C++ program to display the results of rolling an 8-sided die 5 times.
Write a complete C++ program to display the results of rolling an 8-sided die 5 times.
Write a C++ program for the following problem: Calculate and print the area and volume of...
Write a C++ program for the following problem: Calculate and print the area and volume of a cone inside a While  loop that goes from 1 to 20 with a step of .5. (the step is 1/2 or Point 5, so you go 10, 10.5,11, 11.5) Note: Your loop variable will need to be a double data type Use two decimal places on all numbers that are double data type. This will be a table with 3 columns. Don't worry about...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT