11131: 第三章:if选择结构《例题》

Memory Limit:128 MB Time Limit:1.000 S
Judge Style:Text Compare Creator:
Submit:3 Solved:0

Description

从键盘读入一个数,判断它的正负。

输入示例
5
输出示例
+

输入示例
-5
输出示例
-

Input

输入整数n。

Output

是正数,则输出“+”,是负数,则输出“-”。

Sample Input Copy

5

Sample Output Copy

+

HINT

程序:
#include<cstdio>
using namespace std;
int main()
{
    int n;
    scanf("%d",&n);
    if(n>=0)//如果n大于等于0,就执行下面的printf("+");输出+,否则就执行printf("-");
    {
        printf("+");
    }
    else
    {
        printf("-");
    }
    return 0;
}

程序结构:
    if(条件)
    {
        条件满足的时候做什么
    }
    else
    {
        条件不满足的时候做什么
    }
英语单词:
    if:如果
    else:其他(情况)

要求:会默打(一点都不要看教师提供的代码,一个字母错都不行)以上代码,并且多次运行都能输出正确结果。