面瘫女皇倾天下御宅屋:程序题:输出给出数值的奇偶属性
能不能把答案同时再解释一下啊?
是ASP的
temp=shu-(int)(shu/2)*2
if temp=1 then response.write "奇数"
else
if shu-(int)(shu/2)*2=0 then response.write "偶数"
else response.write "不是整数"
end if
end if
boolean(int x)
{
int i;
i=x%2;
if(i)
printf("true");
else
printf("false");
}
说明:这是一个构造函数,在主函数里调用函数 boolean()就行了,例:boolean(t);t是你需要判断的数
c++编写的.你看适合吗.
int main()
{
int y=0;
cout <<"please input the number"<<endl;
cin >> y;
if!(y%2)
cout<<"this is oushu"<<endl;
cout<<"this is jishu"<<endl;
else
cout<<"input the oushu and jishu"<<endl;
}
ASP
完整的代码(将此文件命为num.asp)
<%
num=request("num")
%>
<script language = "VBScript">
function validate_myform()
if document.myform.num.value="" Then
window.alert("请你输入数字!")
document.myform.num.focus()
return false
End If
if not isnumeric(document.myform.num.value) Then
window.alert("非法字符,请你输入数字!")
document.myform.num.focus()
return false
End If
end function
</script>
<FORM METHOD=POST ACTION="num.asp" NAME="myform">
<INPUT TYPE="text" NAME="num"><INPUT TYPE="submit" onfocus="validate_myform()">
</FORM>
<%
i=num mod 2
if num<>"" then
if i=0 then
response.write "你输入的数:"&num&"为偶数"
else
response.write "你输入的数:"&num&"为奇数"
end if
end if
%>
C语言(完整代码)
#include<stdio.h>
main()
{printf("请你输入一个数:");
int a;
scanf("%d",&a);
if(a%2==0)printf("偶数");
else printf("奇数");
}
好了!!