Square terms series
Printing 10 terms of square terms of natural numbers beginning from 1.
Learning Objectives
- Using the series progression logic in the loop.
Source Code
|
|
Run Output
Code Understanding
for(int i=1;i<=10;++i)
This is simple for loop starting from 1 and ending at 10 with step of 1 with each iteration.
cout<<i*i<<” “;
The series logic is simply squaring the loop index number and then adding a space after words.
Notes
- Simple series may use the index number as the term calculator, but for most series applications we can use index for only the term count and term calculation logic may not depend on index number.
Common Errors
- Student make commonย mistake in writing i<10 in place ofย i<=10.
Suggested Filename(s): sq-series.cpp
Created: 8-Jan-2018 01:26 | Updated: 15-Sep-2018 12:47|
