zoukankan      html  css  js  c++  java
  • 第五章 IF语句与逻辑运算符 简单

    /*
    // 4 什么是表达式
    #include <iostream>
    using namespace std;
    int main()
    {
    	for(int i=0; i<=60; i++)
    	{
    		if(i%6 == 0)
    		{
    		   cout<<"\n";
    		}
    		cout<<i<<"\t";
    	}
        return 0;
    }*/
    
    /*
    // 5 赋值运算符与数学运算符
    #include <iostream>
    using namespace std;
    int main()
    {
    	int a=2;
    	a = a *= 6;
    	cout<<a<<endl;
        return 0;
    }
    */
    
    /*
    // 6 什么是自加与自减
    #include <iostream>
    using namespace std;
    int main()
    {
    	int a = 1;
    	cout<<a++<<endl;
    	cout<<a<<endl;
    
    	int b = 11;
    	cout<<b--<<endl;
    	cout<<b<<endl;
        return 0;
    }
    */
    
    /*
    // 7 表达式的优先级
    #include <iostream>
    using namespace std;
    int main()
    {
    	int a = (1+2)*(3+4)*5;
    	cout<<a<<endl;
        return 0;
    }
    */
    
    /*
    // 8 关系运算符
    #include <iostream>
    using namespace std;
    int main()
    {
    	int x = 1, y = 2;
    	if(x >= y){
    	    cout<<x<<endl;
    	}else{
    	    cout<<y<<endl;
    	}
        return 0;
    }
    */
    
    /*
    //9 if语句
    #include <iostream>
    using namespace std;
    int main()
    {
    	int x = 3, y=2;
    	if(x<y)
    	{
    	    cout<<"x不等于y\n";
    		cout<<"y大于x\n";
    		cout<<"x小于y\n";
    	}
    	cout<<"x不等于0\n";
        return 0;
    }
    */
    
    /*
    //10 else语句
    #include <iostream>
    using namespace std;
    int main()
    {
    	int a, b;
    	cout<<"请输入第一个值:"<<endl;
    	cin>>a;
    	cout<<"请输入第二个值:"<<endl;
    	cin>>b;
    	if(a>b)
    	{
    	   cout<<"第一个数比第二个数大"<<endl;
    	}else{
    	   cout<<"第二个数比第一个数大"<<endl;
    	}
    	cout<<"该程序执行完毕"<<endl;
    
        return 0;
    }
    */
    
    /*
    //12 if语句的嵌套
    #include <iostream>
    using namespace std;
    int main()
    {
        cout<<"请佃入一个整数:"<<endl;
    	int x;
    	cin>>x;
    	if(x > 1)
    	{
    	     if(x<100)
    			 cout<<"x大于1小于100"<<endl;
    		 else
    			 cout<<"x大于或者等于100"<<endl;
    	}else{
    	     if(x<1)
    			 cout<<"x小于1"<<endl;
    		 else
    			 cout<<"x等于1"<<endl;
    	}
    }
    */
    
    
    /*
    //16 逻辑非运算符
    #include <iostream>
    using namespace std;
    int main()
    {
       cout<<"请输入一个大于1的整数:"<<endl;
       int x;
       cin>>x;
       if(!x==0){
          cout<<"x不等于0"<<endl;
       }else{
          cout<<"x等于0"<<endl;
       }
       return 0;
    }
    */
    
    // 18 运算式的真假关系
    #include <iostream>
    using namespace std;
    int main()
    {
    	char a ='\0';
    	if(!a)
    	{
    	    cout<<"a的值为0"<<endl;
    	}else{
    	    cout<<"a的值不为0"<<endl;
    	}
        return 0;
    }
    

      

  • 相关阅读:
    Git Bash 下操作文件及文件夹命令
    python django -2 ORM模型
    python django -1
    redis python交互和实际例子
    MongoDB API和python操作
    python mysql 封装
    fabric 自动化部署
    linux 开机自启
    linux shell习题训练
    linux grep sed awk
  • 原文地址:https://www.cnblogs.com/xiangxiaodong/p/2552898.html
Copyright © 2011-2022 走看看