Terms of AP in C++

 Terms of AP In C++

Write a program to print first x terms of the series 3N + 2 which are not multiples of 4.

Input format :

Integer x

Output format :

Terms of series (separated by space)

Constraints :

1 <= x <= 1,000

Sample Input 1 :

10

Sample Output 1 :

5 11 14 17 23 26 29 35 38 41

Sample Input 2 :

4

Sample Output 2 :

5 11 14 17
C++ Code :
#include<iostream>
using namespace std;

int main() {
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		int x=(3*i)+2;
		if(x%4==0)
		{
			n=n+1; 
          continue;
		}
		cout<<x<<" "; 
	}
}



SHARE

Milan Tomic

Hi. I’m Designer of Blog Magic. I’m CEO/Founder of ThemeXpose. I’m Creative Art Director, Web Designer, UI/UX Designer, Interaction Designer, Industrial Designer, Web Developer, Business Enthusiast, StartUp Enthusiast, Speaker, Writer and Photographer. Inspired to make things looks better.

  • Image
  • Image
  • Image
  • Image
  • Image
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment