Asking the user for input for int type variable - C Statement

C examples for Statement:for

Description

Asking the user for input for int type variable

Demo Code

#include <stdio.h>

int main (void)
{
    int n, number, triangularNumber;

    printf ("What triangular number do you want? ");
    scanf ("%i", &number);

    triangularNumber = 0;/*w  ww .  ja  v  a 2 s .  c o m*/

    for (n = 1; n <= number; ++n)
        triangularNumber += n;

    printf("Triangular number %i is %i\n", number, triangularNumber);

    return 0;
}

Result


Related Tutorials