Question

In: Computer Science

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; number<=5; number ++ =2

then it runs again number=2; number <=5; number ++ ) number is 3

then it runs again number=3; number <=5; number ++) number is 4

then it runs again number=4); njmber <=5; number ++) number is 5 and then ends because it hits <=5 and becomes true

so it goes to the next

for (int i=1; i<=number; i++

factorial *=1;

not sure how this works or comes up the mulipliers

Solutions

Expert Solution

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);

outer loop runs for number =1 ro number =5
inner loop runs for i=1 to i=number
now lets trace
number=1
in inner loop
i=1 factorial=1
then loop breaks
hence 1 1 is printed //here number is 1 and factorial is 1
number=2
in inner loop
i=1 factorial =1
i=2 factorial =2 //2x1
then loop breaks
hence 2 2 is printed //here number is 2 and factorial is 2
number=3
in inner loop
i=1 factorial =1
i=2 factorial =2 //2x1
i=3 factorial = 6 //3x2x1
then loop breaks
hence 3 6 is printed //here number is 3 and factorial is 6
number=4
in inner loop
i=1 factorial =1
i=2 factorial =2 //2x1
i=3 factorial = 6 //3x2x1
i=4 factorial = 24 //4x3x2x1
then loop breaks
hence 4 24 is printed //here number is 4 and factorial is 24
number=5
in inner loop
i=1 factorial =1
i=2 factorial =2 //2x1
i=3 factorial = 6 //3x2x1
i=4 factorial = 24 //4x3x2x1
i=5 factorial = 120 //5x4x3x2x1
then loop breaks
hence 5 120 is printed //here number is 5 and factorial is 120


Related Solutions

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.
This is a Java program Problem Description Write an application that inputs five digits from the...
This is a Java program Problem Description Write an application that inputs five digits from the user, assembles the individual digits into a five-digit integer number (the first digit is for one’s place, the second digit is for the ten’s place, etc.) using arithmetic calculations and prints the number. Assume that the user enters enough digits. Sample Output Enter five digits: 1 2 3 4 5 The number is 54321 Problem-Solving Tips The input digits are integer, so you will...
I have entered this line of code for exercise 6-8 saying to Write an application that...
I have entered this line of code for exercise 6-8 saying to Write an application that allows a user to enter any number of student quiz scores, as integers, until the user enters 99. If the score entered is less than 0 or more than 10, display Score must be between 10 and 0 and do not use the score. After all the scores have been entered, display the number of valid scores entered, the highest score, the lowest score,...
I have to write report about Application of Linear Algebra in Electronic Engineering. Let me know...
I have to write report about Application of Linear Algebra in Electronic Engineering. Let me know about the examples simply and variously as possible as you can.
I have to write an initial algorithm and a refined algorithm for the following problem: Display...
I have to write an initial algorithm and a refined algorithm for the following problem: Display the square of numbers from 0 to some user inputted value. For example if the user enters 3 then the program will need to display the square of 0, 1, 2 and 3. Must use a counter loop. Must use 2 methods. One method that gets the number from the user and returns it. A second method is passed that number as a parameter...
Instruction: For this problem, you may leave your answer as as unsimplified expressions with factorials, exponents,...
Instruction: For this problem, you may leave your answer as as unsimplified expressions with factorials, exponents, binomial coefficients, etc. However, you still need to include a brief justification for your results. (40 points - parts (a)–(h): 4 points each; part (h): 8 points In a futuristic dystopian Chicago, society is divided into five factions: Abnegation, Amity, Candor, Dauntless and Erudite. At the age of 16, each person is allowed to choose any faction as their permanent social group at the...
Factorials in Java: Write out your Program Design for how to automate the testing. The objective...
Factorials in Java: Write out your Program Design for how to automate the testing. The objective is to repeat the factorial calculation for different values of n, as n changes from 2, 3, 4, 5, 6, 7.. 1) test for an int 2) test for a long 3)test for a double
Answer these using VISUAL STUDIOS not CTT or PYTHON 1.Write an expression that evaluates to true...
Answer these using VISUAL STUDIOS not CTT or PYTHON 1.Write an expression that evaluates to true if the value of the integer variable x is divisible (with no remainder) by the integer variable y. (Assume that y is not zero.) 2.Write an expression that evaluates to true if the value of the integer variable numberOfPrizes is divisible (with no remainder) by the integer variable numberOfParticipants. (Assume that numberOfParticipants is not zero.) 3.Write an expression that evaluates to true if the...
hi I have search on IKEA Company and I have to write about below information 1-...
hi I have search on IKEA Company and I have to write about below information 1- Describe the roles of directional,marketing, operations and human resource strategies in the overall well-being of your selected company?
So I have written a code for it but i just have a problem with the...
So I have written a code for it but i just have a problem with the output. For the month with the highest temperature and lowest temperature, my code starts at 0 instead of 1. For example if I input that month 1 had a high of 20 and low of -10, and every other month had much warmer weather than that, it should say "The month with the lowest temperature is 1" but instead it says "The month with...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT