openjudge/ 1.4编程基础之逻辑表达式与条件分支 1-5

openjudge/ 1.4编程基础之逻辑表达式与条件分支 1-5_第1张图片

01:判断数正负

#include
using namespace std;
int main(){
	int n;
	scanf("%d",&n);
    if(n>0)
		cout<<"positive"<

02:输出绝对值

#include
#include
using namespace std;
int main(){
	double n;
	cin>>n;
	if(n>=0)
		printf("%.2lf\n",n);
	else 
		printf("%.2lf\n",abs(n));
	return 0;
}

03:奇偶数判断

#include
using namespace std;
int main(){
	int n;
	cin>>n;
	if(n%2==1)
		cout<<"odd";
	else 
		cout<<"even";
	return 0;
}

04:奇偶ASCII值判断

#include   
using namespace std;  
int main(){  
    char ch;  
    ch = getchar();  
    if (ch%2 == 0) cout << "NO" << endl;  
    else cout << "YES" << endl;  
    return 0;  
}  

05:整数大小比较

#include
using namespace std;
int main(){
	int a,b;
	cin>>a>>b;
	if(a>b)cout<<'>';
	else if(a==b)cout<<'=';
	else cout<<'<';
	return 0;
}

 

你可能感兴趣的:(openjudge)