Experiment 3-2 Calculate the value of the sign function (10 points)

For any integer n, the symbolic function (is defined as follows:

Please write a program to calculate the value of this function for any input integer.

Input format:

The input gives the integer n on one line.

Output format:

The function value corresponding to the integer n is output in a line according to the format "sign (n) = function value".

Input example 1:

10
 

Sample output 1:

sign(10) = 1
 

Input example 2:

0
 

Sample output 2:

sign(0) = 0 
 

Input example 3:

-98
 

Sample output 3:

sign(-98) = -1



#include<stdio.h>
int main ()
{
    int n,x;
    scanf("%d",&n);
    if(n<0)
    {
        x=-1;
    }else if(n==0)
    {
        x=0;
    }else
    {
        x=1;
    }
    printf("sign(%d) = %d",n,x);
    return 0;
}

Guess you like

Origin www.cnblogs.com/wven/p/12686836.html