Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
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?
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started