-->
Showing posts with label 6. Show all posts
Showing posts with label 6. Show all posts

program to print/display 1,6,11,16....nth term.

//program to print/display 1,6,11,16....nth term.
#include<stdio.h>
#include<conio.h>
void main()
{
int k=1,n;
printf("enter value of 'n'\n");
scanf("%d",&n);
while(k<=n)
   {
      printf("%d,",k);
      k=k+5;
   }
getch();
}

program to print/display 2,4,6,8,10,12... to 15th term.

//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();
}