In: Computer Science
1-
Write a program that will display the following series of integers using iterative statement of your choice, and terminate the iteration once it is larger than 200.
1, 3, 7, 13, 21, 31, 43, …
use only C++!!
Code:
#include <iostream>
using namespace std;
int main()
{
int num=1,iter=1; //declare num and iter variables and initalize to
1
while(num<=200) //iterate the loop till num less than or equl to
200
{
cout << num << " "; //print the num
num=num+(2*iter); //increment the number by adding 2*iter value to
number
iter++; //increment iter count
}
return 0;
}
Code and Output Screenshots:
Note: if you have any queries please post a comment thanks a lot..always available to help you..