if-else语句 [英] if-else statement
问题描述
无法弄清楚如何制定正确的语法..我可以在循环语句中完成它但我的教授说只使用简单的if-else语句。问题是这样的。编写一个程序,确定你输入的数字是奇数还是偶数..
我试着编写这段代码..
#include< stdio.h>
main()
{
int nos;
clrscr();
printf(" Enter number:");
scanf("%d",& nos);
if(nos ++){
printf(" Odd number");
}
else {
printf(偶数);
}
getch();
}
Just cant figure out how to formulate the correct syntax..I can do it in looping statement but my professor said that use only the simple if-else statement. The problem goes like this..Write a program that will determine if the number that you entered is either odd or even number..
I tried writing this code..
#include<stdio.h>
main()
{
int nos;
clrscr();
printf("Enter number:");
scanf("%d",&nos);
if(nos++){
printf("Odd number");
}
else {
printf("Even number");
}
getch();
}
推荐答案
这是查找奇数甚至是简单的方法
this is the simple way of finding odd or even
这是一种简单的查找方式奇数或偶数
this is the simple way of finding odd or even
在您的scanf函数中,您有一个&而不是%
应该是:scanf("%d"& nos);
In your scanf function you have an & instead of a %
it should be: scanf("%d",&nos);
这篇关于if-else语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!