Write a program (WAP) that will print following series upto Nth terms.
1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31 …….
Sample input Sample output
2 1, 3
5 1, 3, 5, 7, 9
11 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21
Answers
Answered by
7
Answer:
The given code is written in Java.
import java.util.*;
public class Series{
public static void main(){
Scanner _=new Scanner(System.in);
System.out.print("Enter n - ");
int n=_.nextInt();
_.close();
for(int i=1;i<=2*n-1;i+=2)
System.out.print(i+" ");
}
}
\texttt{\textsf{\large{\underline{Logic}:}}}
Logic
:
Accept the limit from user, say n.
Repeat from i = 1 to 2 * n - 1:
Display the value of i.
Increment the value of i by 2.
See the attachment for output.
Explanation:
hope it will be helpful for you if yes then please mark as brainliest (•‿•)
Similar questions