C 程式設計檢查一個數字是正數、負數還是 0?
大於 0 的數字為正數,小於 0 的數字為負數。正負概念在數論和程式設計中非常重要。計算僅依賴於此概念。
Input: 0 Output:0 is zero
說明
使用條件語句檢查數字與 0 的關係,是大於 0 還是小於 0。
示例
#include <iostream>
using namespace std;
int main() {
int n=0;
if(n>0) {
printf("%d is positive",n);
} else if(n<0) {
printf("%d is negative",n);
} else {
printf("%d is zero",n);
}
return 0;
}
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
JavaScript
PHP