//program to print/display 2,4,6,8,10,12... to 15th term.
#include<stdio.h>
#include<conio.h>
void main()
{
int k=2;
while(k<=15)
{
printf("%d,",k);
k=k+2;
}
getch();
}
Or
you can use following method.
first term(a)=2
common difference(d)=2
number of terms(n)=15
here we can see that given series is in arithmetic progression so nth term=a+(n-1)*d.It gives us nth term=30 i.e.
last term will be 30.
We put 30 in while loop
//program to print/display 2,4,6,8,10,12... to 15th term.
#include<stdio.h>
#include<conio.h>
void main()
{
int k=2;
while(k<=30)
{
printf("%d,",k);
k=k+2;
}
getch();
}
#include<stdio.h>
#include<conio.h>
void main()
{
int k=2;
while(k<=15)
{
printf("%d,",k);
k=k+2;
}
getch();
}
Or
you can use following method.
first term(a)=2
common difference(d)=2
number of terms(n)=15
here we can see that given series is in arithmetic progression so nth term=a+(n-1)*d.It gives us nth term=30 i.e.
last term will be 30.
We put 30 in while loop
//program to print/display 2,4,6,8,10,12... to 15th term.
#include<stdio.h>
#include<conio.h>
void main()
{
int k=2;
while(k<=30)
{
printf("%d,",k);
k=k+2;
}
getch();
}