
Data Structures and Algorithms: An Introduction 85
Input: N, K
Output: sumSeries
The program is given below:
/* This program computes the sum of a series */
#include <stdio.h>
void main()
{
int sumSeries, i;
int N; /* Number of terms */
int K; /* The integer multiple*/
printf(“\n Enter Number of terms and Integer Multiple”);
scanf (“%d %d”, &N,&K);
sumSeries = 0; /*Accumulator initialized */
For (i=1; i<=N; i++)
{
sumSeries = sumSeries + i*K;
}
printf (“\n The sum of first %d terms = %d”, N, sumSeries);
}
In fact, it can be concluded that irrespective of the programming paradigms, a general algorithm is
designed based on following constructs:
(1)