Calculating the Absolute Value of an Integer. - C Statement

C examples for Statement:if

Description

Calculating the Absolute Value of an Integer.

Demo Code

#include <stdio.h>

int main (void)
{
    int number;//from ww  w.  j a  va 2 s. c  o m

    printf ("Type in your number: ");
    scanf ("%i", &number);

    if (number < 0)
        number = -number;

    printf ("The absolute value is %i\n", number);

    return 0;
}

Result


Related Tutorials