Question

Write a program in C that calculates: n! = n*(n-1)*(n-2) ...3 ...2 ...1 Use for loop...

Write a program in C that calculates:
n! = n*(n-1)*(n-2) ...3 ...2 ...1

Use for loop and while loop

Homework Answers

Answer #1

CODE IN C:

#include <stdio.h>

int main()
{
int n;
printf("Enter the value of n : ");
scanf("%d",&n);
int fac=1; //initially factorial is taken to be 1
for(int i=1;i<=n;i++)//for loop
{
fac=fac*i;//calculating factorial value
}
printf("The value of fac using for loop is : %d",fac);
printf("\n");
int fac2=1;//initially factorial is taken to be 1
int i=1;
while(i<=n) //while loop
{
fac2=fac2*i;
i++;
}
printf("The value of fac using while loop is : %d",fac2);
}

OUTPUT SNIPPET:

Please give an upvote if you liked my solution.

Thank you :)

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Please write it in c# program please and if possible no arrays only loops Loop Introduction...
Please write it in c# program please and if possible no arrays only loops Loop Introduction Assignment Using the conditions below, write one program that calculates a person’s BMI. Your main() function will call functions 1, 2, and 3. Your program will contain three functions: Function #1: Will ask the user for their weight in pounds and their height in inches.   Your function will convert the weight and height into Body Mass Index (BMI). The formula for converting weight into...
Python code Write a complete program with for loop which calculates the sum of the numbers...
Python code Write a complete program with for loop which calculates the sum of the numbers from 1 to 100
* Write a Java program that calculates and displays the Fibonacci numbers * First prompt the...
* Write a Java program that calculates and displays the Fibonacci numbers * First prompt the user to input a number, N * Then use a for loop to calculate and display the first N fibonocci numbers * For example, if the user enters 5, the output should be: * 1, 1, 2, 3, 5 * * if the user enters 10, the output should be: * 1, 1, 2, 3, 5, 8, 13, 21, 34, 55
C++ PROBLEM: Create a program that calculates the hyperfactorial of any positive integer n, where the...
C++ PROBLEM: Create a program that calculates the hyperfactorial of any positive integer n, where the hyperfactorial is equivalent to value obtained by the operation: 1^1*2^2*3^3*…..n^n . If user inputs the value that is not a positive value, display a message informing the user that the input is not valid and request a new input. Calculate the hyperfactorial first by creating a program that uses only nested “For loop” structure.
C++ Write a program that calculates and prints the total grade for n assignments as a...
C++ Write a program that calculates and prints the total grade for n assignments as a percentage. Prompt the user to enter the value of n, followed by the number of points received and number of points possible for each assignment . Calculate and print the total number of points received, total number of points possible, and the overall percentage: (total points received / total points possible) * 100. Output: Enter·number·of·assignments·to·input:3↵ Enter·number·of·points·received·for·assignment·1 :10↵ Enter·number·of·possible·points·for·assignment·1 :10↵ Enter·number·of·points·received·for·assignment·2 :7↵ Enter·number·of·possible·points·for·assignment·2 :12↵ Enter·number·of·points·received·for·assignment·3...
Write a C program that calculates and displays the sum of all fourdigit numbers in the...
Write a C program that calculates and displays the sum of all fourdigit numbers in the line. The only include to use is <stdio.h>. The only keywords:void, int, char, while,if, else, and return. The only library functions:printf(), getchar().The only predefined constant:EOF. Input            output 3153\n           3153 00020005\n 7 999578585    error 456 5443       error 6574y435      error
using C++ 1) write a program to calculate to avg of N number of subjects. 2)write...
using C++ 1) write a program to calculate to avg of N number of subjects. 2)write a program to find the factorial of 5! 5*4*3*2*1 3)write a program to display the multiplication table for any number please enter number : 3 1*3=3 2*3=6 2*4= 10*3=30 4) find the factorial on n
Step 2 Exercise - Using while loop:    Write a Java program (using while loop) to display...
Step 2 Exercise - Using while loop:    Write a Java program (using while loop) to display 5 lines of smiley faces. The following would be the output of your program: Note: Sample program is in the "Important Documents", Module 6 folder) Hello:                          Bye!
Write a program that finds and prints all of the prime numbers between 3 and X...
Write a program that finds and prints all of the prime numbers between 3 and X (X is input from the user). A prime number is a number such that 1 and itself are the only numbers that evenly divide it (for example, 3, 5, 7, 11, 13, 17, …). One way to solve this problem is to use a doubly nested loop (a loop inside another loop). The outer loop can iterate from 3 to N while the inner...
Using a while loop, write a program that reads 10 integer numbers. The program shall count...
Using a while loop, write a program that reads 10 integer numbers. The program shall count how many of them are multiples of 2, how many are multiples of 3, and how many are NOT multiples of either 2 or 3. The output should be similar to the one shown below. c++ language
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT