#include <stdio.h>
/* no prototype needed, but add them here if desired */
int Triangular_Number (int);
//*********************************************************************
//
// Function: Triangular_Number
//
// Description: A triangular number can be generated by the
// the following formula:
//
// Triangular number = n (n + 1) / 2
//
// This function will return the triangular number
// calculated based it being passed an integer value
//
// Parameters: theNumber - An integer value to start the
// calculation of the Triangular Number.
//
// Returns: The Triangular Number that is calculated
//
//*********************************************************************
int Triangular_Number (int theNumber)
{
int tri_num; /* triangular number to be calculated */
/* Calculate the Triangular Number */
tri_num = (theNumber * (theNumber + 1))/2;
/* return to the calling function */
return(tri_num);
} /* end Triangular_Number */
int main (void)
{
int n; /* a number to calculate a triangular number */
int tri_num; /* The triangular number calculated from n */
printf ("TABLE OF TRIANGULAR NUMBERS from 5 to 50 by 5\n\n"); printf (" n Triangular Number\n"); printf ("--- -----------------\n");
tri_num = 0;
/* Calculate and print triangular numbers from 5 to 50 in steps of 5 */
for (n = 5; n <= 50; n += 5)
{
printf (" %-5i %-5i\n", n
, Triangular_Number
(n
)); }
return (0); /* indicate successful completion */
} /* end main */