C program to generate series -1 4 -7 10 -13 16........till N - My CS Tutorial - My CS Tutorial

Breaking

Programming languages full tutorial and programs, exam papers, visual basic( Vb.net ), information of new technologies and more....

Sunday, December 8, 2019

C program to generate series -1 4 -7 10 -13 16........till N - My CS Tutorial

In this tutorial we will learn how to write a c program that generate the series  -1 4 -7 10 -13 16.................till N.


C program code


#include<stdio.h>
#include<conio.h>
void main()
{
 int a,b=1,terms;
 printf("\n Enter number of terms in series:\n ");
 scanf("%d",&terms);
  printf("\n ");
 for(a=1;a<=terms;a++)
 {
  if(a%2==1)
  printf("%d ",(-1*b));
  else
  printf("%d ",b);
  b+=3;
 }
 printf("\n");
 getch();
}


OUTPUT:






In this output the value of terms in series is 15

And the series is:

 -1 4 -7 10 -13 16 -19 22 -25 28 -31 34 -37 40 -43


Please share this post and blog link with your friends.For more programs use this blog.
If you have any problem, please comment in comment box, subscribe this blog for notifications of new post on your email and follow this blog.

Created by-- HARSH CHAUHAN

No comments:

Post a Comment