Write a program to find the following series upto n terms:
13,28,43....
Logic is required. No irreverent answer please.
Answers
Answer:
import java.util.*;
public class Series
{
public static void main(String args[ ])
{
Scanner in=new Scanner (System. in);
int a=15,b,c,n;
System.out.println("Enter the value of n");
n=in.nextInt();
for(b=1;b<=n;b++)
{
c=(a*b)-2;
System.out.println("The series is ="+c);
}
}
}
Explanation:
In the given series it is the subtractive result of 2 from the multiples of 15.
Such that,
(15×1)-2
=15-2
=13
(15×2)-2
=30-2
=28
(15×3)-2
=45-2
=43
And vice versa.
Answer:
main()
{
int loop_var, n, sum;
printf("\n Enter the number of terms to print:");
scanf("%d",&n);
sum=13;
printf("\n");
for(loop_var=1;loop_var<=n;loop_var++)
{
printf("%d",sum);
sum= sum+15;
}
}
Explanation:
set sun = 13, then with each iteration increase the value by 15 and print the value. The iteration starts at 1 and goes till n so at the end there would be n terms starting with 13.