c++编程:
#include "iostream.h"
void main()
{
int n;
cout<<"请输入一个整数:";
cin>>n;
if(n>0&&n%2==0)cout<
vb编程:
Private Sub Form_click()
Dim n As Integer
n = InputBox("请输入一个整数", "输入框")
If n > 0 And n Mod 2 = 0 Then
Print n; "是正偶数"
ElseIf n > 0 And n Mod 2 = 1 Then
Print n; "是正奇数"
ElseIf n < 0 And ((-1) * n) Mod 2 = 0 Then
Print n; "是负偶数"
ElseIf n < 0 And ((-1) * n) Mod 2 = 1 Then
Print n; "是负奇数"
End If
If n = 0 Then
Print "0无谓正负奇偶"
End If
End Sub
#include
main()
{
int x;
scanf("%d",&x);
if(x>0 && 0==x%2)
printf("x为正偶数\n");
else if(x>0 && 1==x%2)
printf("x为正奇数\n");
else if(x<0 && 0==x%2)
printf("x为负偶数\n");
else if(x<0 && 1==x%2)
printf("x为负奇数\n");
else
printf("您输入的数值为0\n");
}
正负性,可以用所输入的数和0比较分三种情况,大于0 , 小于0 ,等于0
奇偶性,就用该数去模2
这样子就好了!
#include
main()
{
int
x,y;
printf("Please
input
a
integer:");
/*输入一个整数!*/
scanf("%d",x);
if(x<0)
printf("It's
a
negative
number!");
/*输入的数是负数!*/
else
printf("It's
a
positive
number!");
/*输入的数是正数!*/
y=x%2;
if(0==y)
printf("It's
a
even
number!");
/*输入的数是偶数!*/
else
printf("It's
a
odd
number!");
/*输入的数是奇数!*/
}
右边的是注释!
0是偶数,怎么无谓正负奇偶?
还有,程序中写(-1)*n%2干什么,负数也可以%2的嘛。