Question: To earn discussion points post sample code in two versions: for loop and while loop. Add one line comment to explain what the code is

To earn discussion points post sample code in two versions: for loop and while loop. Add one line comment to explain what the code is doing. Code using for loops (and while) is a great place to practice compound assignments. Here is an example: // factorial of n -- assuming all vars are declared int, n has been input and is >=0 tot=1 for (int i=n; i>0; i--){ tot*=i; } printf(factorial of %d is %d , n,tot); // using while i=n; tot=1 while (i >0) { tot*=i; i--; } printf(factorial of %d is %d , n,tot); // there's one difference between the two codes; what is it?

Please give an example other than the sample, and simple explanation. laymans terms

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!