Terms of AP
Send Feedback
Write a program to print first x terms of the series 3N + 2 which are not multiples of 4.
N varies from 1 to 1000.
Input format :
Output format :
Sample Input 1 :
Sample Output 1 :
Sample Input 2 :
Sample Output 2 :
import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
Scanner s = new Scanner(System.in);
int n = s.nextInt();
int count = 0;
for(int i=1; count<n;i++)
{
int ap = 3*i+2;
if(ap%4!=0)
{
System.out.print(ap+" ");
count++;
}
}
}
}
No comments:
Post a Comment