Calcd [PTA] 7-16 sign function (10 minutes)

For any integer n, the definition of a sign function sign (n) as follows:
Here Insert Picture Description

Write a program to calculate a function of the input value of any integer.

Input format:
input integer n in the given row.

Output format:
the output function value corresponding to the integer n in the format "sign (n) = function value" in a row.

Input Example 1:
10

Sample Output. 1:
Sign (10). 1 =

Input Sample 2:
0

Output Sample 2:
Sign (0) = 0

Input Sample 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;
}
Published 48 original articles · won praise 0 · Views 327

Guess you like

Origin blog.csdn.net/weixin_46399138/article/details/105332581
Recommended