C Program To Calculate The Series 3+9+12+...+N


♣ Try it Out ::
#include<stdio.h>
#include<conio.h>

int SeriesSum(int n)
{
    if(n == 0) return(0);
    else return(n+SeriesSum(n-3));
}

int main()
{
    int num, i;

    printf("Enter the n\'th number (N will be a multiple of 3): ");
    scanf("%d", &num);

    printf("\nSeries: ");
    for(i=3; i<=num; i+=3) {
        printf("%d", i);
        (i == num) ? printf(" = %d", SeriesSum(num)) : printf(" + ");
    }

    getch();
    return(0);
}

♣ Output ::
Enter the n'th number (N will be a multiple of 3): 27

Series: 3 + 6 + 9 + 12 + 15 + 18 + 21 + 24 + 27 = 135

♣ Downloads ::

Comments

Popular posts from this blog

C++ :: Topological Sort Algorithm (using DFS)

How to Hack Facebook Account

C++ :: Strongly Connected Components Algorithm (SCC)