问题描述
程序总是显示输入是奇数。
int main()
{
int n,d ;
printf("输入数字:");
scanf("%d",& n);
d = 1;
if(d == n)
{
printf(" number is odd\\\
) ;);
}
否则if(d< n)
{
for(; d< n; d + = 2);
printf(数字是奇数);
}
其他
{
printf(数字是偶数);
}
-
Mustafa El Sayid
The program always shows that the input is odd.
int main ()
{
int n, d;
printf ("Enter a Number: ");
scanf ("%d", &n);
d=1;
if (d==n)
{
printf ("The number is odd\n");
}
else if (d < n)
{
for (; d<n; d+=2);
printf ("The number is odd\n");
}
else
{
printf ("The number is even\n");
}
--
Mustafa El Sayid
推荐答案
不,它不是。尝试输入0.
您可能想要查找模运算符,BTW。
Richard
No, it doesn''t. Try entering 0.
You might want to look up the modulo operator, BTW.
Richard
这应该适用于二合一机器:
#include< stdio.h>
int main(无效)
{int n;
printf(" ;输入一个数字:);
scanf("%d",& n);
printf(" n is%s \ n" ,(n& 1)?奇数:偶数;;
返回0;
}
-
Morris Dovey
DeSoto Solar
美国爱荷华州DeSoto
不,它不是。尝试输入0.
您可能想要查找模运算符,BTW。
Richard
No, it doesn''t. Try entering 0.
You might want to look up the modulo operator, BTW.
Richard
尝试输入2或更高的偶数。
-
Mustafa Zaza
Try entering 2 or any higher even number.
--
Mustafa Zaza
这篇关于偶数或奇数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!