bsc

Comprehensive codebase and cou...
Log | Files | Refs | README | LICENSE

pc-ip-03.c (679B)


      1 /*
      2  * Author: Amit Dutta (amitdutta4255@gmail.com) | Date: 05 Jan 2026
      3  * Repo: https://github.com/notamitgamer/bsc
      4  * License: MIT
      5  */
      6 
      7 /*
      8  * Question 3:
      9  * Write a program to compute the sum of the first n terms of the series using a function: S=1-2+3-4+5-6+...
     10  */
     11 
     12 #include <stdio.h>
     13 
     14 int series(int);
     15 
     16 int main()
     17 {
     18     int n;
     19     printf("Enter the n: ");
     20     scanf("%d", &n);
     21     printf("\nSum of the series: %d", series(n));
     22     return 0;
     23 }
     24 
     25 int series(int n)
     26 {
     27     int i, result = 0;
     28     for (i = 1; i <= n; i++)
     29     {
     30         if (i % 2 == 0)
     31         {
     32             result -= i;
     33         }
     34         else
     35         {
     36             result += i;
     37         }
     38     }
     39     return result;
     40 }
© notamitgamer • Site Built: 2026-07-21 13:58:23 UTC • git-mirror commit: 1037f62 [view raw info]
Originally created with stagit • modified by notamitgamer
Forked from github.com/notamitgamer/git-mirror