NOI / 1.4编程基础之逻辑表达式与条件分支【全部】

01:判断数正负

描述

给定一个整数N,判断其正负。

输入

一个整数N(-109 <= N <= 109)

输出

如果N > 0, 输出positive;
如果N = 0, 输出zero;
如果N < 0, 输出negative

样例输入

1

样例输出

positive
#include <iostream>
#include <cstdio>
#include <math.h>
using namespace std;

int main(){

    int N;
    cin>>N;

    if(N>0){
        cout<<"positive"<<endl;
    }else if(N==0){
        cout<<"zero"<<endl;
    }else{
        cout<<"negative"<<endl;
    }

	return 0;
}

02:输出绝对值

描述

输入一个浮点数,输出这个浮点数的绝对值。

输入

输入一个浮点数,其绝对值不超过10000。

输出

输出这个浮点数的绝对值,保留到小数点后两位。

样例输入

-3.14

样例输出

3.14
#include <iostream>
#include <cstdio>
#include <math.h>
using namespace std;

int main(){

    double n;
    cin>>n;
    if(n<0){//不能写<=,不然输入0结果是-0,Wrong Answer.
        printf("%.2lf",-n);
    }else{
        printf("%.2lf",n);
    }

	return 0;
}

03:奇偶数判断

描述

给定一个整数,判断该数是奇数还是偶数。

输入

输入仅一行,一个大于零的正整数n。

输出

输出仅一行,如果n是奇数,输出odd;如果n是偶数,输出even。

样例输入

5

样例输出

odd
#include <iostream>
#include <cstdio>
#include <math.h>
using namespace std;

int main(){

    int n;
    cin>>n;
    if(n%2 != 0){
       cout<<"odd"<<endl;
       }else{
       cout<<"even"<<endl;
       }

	return 0;
}

04:奇偶ASCII值判断

描述

任意输入一个字符,判断其ASCII是否是奇数,若是,输出YES,否则,输出NO
例如,字符A的ASCII值是65,则输出YES,若输入字符B(ASCII值是66),则输出NO

输入

输入一个字符

输出

如果其ASCII值为奇数,则输出YES,否则,输出NO

样例输入

A

样例输出

YES
#include <iostream>
#include <cstdio>
#include <math.h>
using namespace std;

int main(){

    char n;
    scanf("%c",&n);
    if(n%2 != 0){
        cout<<"YES"<<endl;
    }else {
        cout<<"NO"<<endl;
    }

	return 0;
}

05:整数大小比较

描述

输入两个整数,比较它们的大小。

输入

一行,包含两个整数x和y,中间用单个空格隔开。
0 <= x < 2^32, -2^31 <= y < 2^31。

输出

一个字符。
若x > y,输出 > ;
若x = y,输出 = ;
若x < y,输出 < ;

样例输入

1000 100

样例输出

>
#include <iostream>
#include <cstdio>
#include <math.h>
using namespace std;

int main(){

    int x,y;
    cin>>x>>y;
    if(x > y){
            cout<<">"<<endl;
    }else if(x == y){
        cout<<"="<<endl;
    }else{
        cout<<"<"<<endl;
    }

	return 0;
}

06:判断是否为两位数​​​​​​​

描述

判断一个正整数是否是两位数(即大于等于10且小于等于99)。

输入

一个正整数,不超过1000。

输出

一行。若该正整数是两

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值