Skip to content

Commit 30b8c6e

Browse files
authored
Create Terms of AP
1 parent 46b4ce1 commit 30b8c6e

File tree

1 file changed

+38
-0
lines changed
  • Lecture 6: Operators and For Loop/Assignment

1 file changed

+38
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
Write a program to print first x terms of the series 3N + 2 which are not multiples of 4.
2+
Input format :
3+
Integer x
4+
Output format :
5+
Terms of series (separated by space)
6+
Constraints :
7+
1 <= x <= 1,000
8+
Sample Input 1 :
9+
10
10+
Sample Output 1 :
11+
5 11 14 17 23 26 29 35 38 41
12+
Sample Input 2 :
13+
4
14+
Sample Output 2 :
15+
5 11 14 17
16+
17+
18+
CODE:
19+
20+
#include<iostream>
21+
using namespace std;
22+
23+
int main() {
24+
// Write your code here
25+
int n;
26+
cin>>n;
27+
int i,term;
28+
int count=1;
29+
for(i=1; count<=n; i++){
30+
term=3*i+2;
31+
if(term%4!=0){
32+
cout<<term<<" ";
33+
count++;
34+
}
35+
36+
}
37+
38+
}

0 commit comments

Comments
 (0)