Simple descending order series – CSKC
Sign In

Search

Code Learning #CPP#2459    siteicon   siteicon  

Simple descending order series

Printing a descending order series – Numbers divisible by 3 from 30 to 1.

Learning Objectives

  • Series printing in the descending order.

Source Code

TC++ #2459

 

Source Code

×

Ask AI About This Code

Default Prompt that is passed along with the code is given below, You can write your own prompt if you so desire.



×

Test CPP

Code Understanding

int start=30,upto=1;
Variable start has been set at 30 and the variable upto has been set at 1. For descending order series the start will be more than the upto variable

for(int i=start;i>=upto;–i)
Here the initialisation will be from higher variable and condition check is with lower variable so >= operator has been used. In the third part of loop –i decrementing has been done so that the descend happens.
{
if(i%3==0) cout<<i<<” “;
This is divisibility test. Here any given instruction set to perform the given task can be performed.
}

Notes

  • Most descending series or loops will have > or >= operator as condition check. However this is problem specific.

Common Errors

  • Student commit frequent errors in >= operator and –i decrement use. Watch carefully and perform a dry run on these kind of loops with test conditions from higher to lower values.


Suggested Filename(s): ser-desc.cpp



Share

Created: 10-Jan-2018 21:47 | Updated: 15-Sep-2018 13:25|