Problem Description

在 BASIC 語言中有一個 SGN 函數,(VB .Net 改成 Math.Sign),它會根據參數的正負號傳回 1, 0, 或 -1。請你寫一個程式來模仿這個函數,給你一個整數 n,若 n > 0 請輸出 1,若 n = 0 請輸出 0,若 n < 0 請輸出 -1。 

The Input

輸入只有一行,其中含有一個整數。

The Output

依題目說明,請輸出 1、0、或 -1。

Sample Input

-9

Sample Output

-1

-----* Problem from【ZeroJudge, an Online Judge System For Beginners

My Answer

 
1
2
3
4
5
6
7
8
9
10
11
12
  #include<iostream>
using namespace std;
int main(void)
{
  int n;
  while(cin>>n){
    (n>0) ? cout<<"1"<<endl
      : (n==0) ? cout<<"0"<<endl
        : cout<<"-1"<<endl;
  }
  return 0;
}
 

 

 


arrow
arrow
    全站熱搜

    兔老大 發表在 痞客邦 留言(0) 人氣()