Implement the sign function. - C Statement

C examples for Statement:if

Description

Implement the sign function.

Demo Code

#include <stdio.h>

int main (void)
{
    int number, sign;

    printf ("Please type in a number: ");
    scanf ("%i", &number);

    if (number < 0)
        sign = -1;//from  w  w  w  .  jav a 2s . com
    else if (number == 0)
        sign = 0;
    else
        sign = 1;

    printf ("Sign = %i\n", sign);

    return 0;
}

Result


Related Tutorials