关于vc++6.0的if语句与scanf语句(初学者必备)

时间:2026-02-14 02:07:16

1、首先建立一个简单的hello world程序,定义一个供if判断的变量(必须是字符型或整型),如 int a=2;再用scanf语句 scanf("%d",&a);其中%d为整型格式,&为取地址符。

关于vc++6.0的if语句与scanf语句(初学者必备)

2、之后就是if语句

#include "stdafx.h"

int main(int argc, char* argv[])

{

int a=2;

scanf("%d",&a);

if(a==1)

{printf("您输入的a=1\n");}

else if(a==2)

{printf("您输入的a=2\n");}

else 

{printf("您输入的a不是1也不是2 \n");}

return 0;

}

关于vc++6.0的if语句与scanf语句(初学者必备)

3、当a=1的运行结果

当a非1,非2的运行结果

关于vc++6.0的if语句与scanf语句(初学者必备)

关于vc++6.0的if语句与scanf语句(初学者必备)

4、若是if(a)

括号内无比较符号,即是a是否为0,或“非0”。0为假,非0为真。

#include "stdafx.h"

int main(int argc, char* argv[])

{

int a=2;

scanf("%d",&a);

if(a)

{printf("您输入的a是非0\n");}

else 

{printf("您输入的a是0\n");}

return 0;

}

关于vc++6.0的if语句与scanf语句(初学者必备)

关于vc++6.0的if语句与scanf语句(初学者必备)

© 2026 五度知识库
信息来自网络 所有数据仅供参考
有疑问请联系站长 site.kefu@gmail.com