#include <stdio.h> int main(){ int a, b, flag; scanf("%d %d", &a, &b); flag = a > b; //flag保存关系运算结果 printf("flag = %d\n", flag); return 0; }运行结果:
#include <iostream> using namespace std; int main(){ int a, b; bool flag; //定义布尔变量 cin>>a>>b; flag = a > b; cout<<"flag = "<<flag<<endl; return 0; }10 20↙
#include <iostream> using namespace std; int main(){ bool flag = true; if(flag){ cout<<"true"<<endl; }else{ cout<<"false"<<endl; } flag = false; if(flag){ cout<<"true"<<endl; }else{ cout<<"false"<<endl; } return 0; }运行结果:
本文链接:http://task.lmcjl.com/news/6440.html