program to compute the sum of first n terms of the following series s=1-2+3-4+5+... Gain Infiniti

program to compute the sum of first n terms of the following series s=1-2+3-4+5+...



   #include<stdio.h>
   #include<conio.h>      
   main()
  {
     clrscr();
   int i,n,sum=1,sine=-1;
   printf("\n enter any integer:");
   scanf("%d",&n);
   for(i=2;i<=n;i++)
   {
   sum=sum+(i*sine);
   sine=sine*(-1);
   }
   printf("\n series is %d",sum);
   getch();
   return 0;
  }

0 comments:

Post a Comment

Twitter Delicious Facebook Digg Stumbleupon Favorites More

 

Design By Manish and Ranjan