C examples for Function:Function Definition
Calculating the nth Triangular Number
#include <stdio.h> void calculateTriangularNumber (int n){ int i, triangularNumber = 0; for (i = 1; i <= n; ++i) triangularNumber += i;// w w w. j a va 2s . co m printf("Triangular number %i is %i\n", n, triangularNumber); } int main (void) { calculateTriangularNumber (10); calculateTriangularNumber (20); calculateTriangularNumber (50); return 0; }