zoukankan      html  css  js  c++  java
  • c语言学习的第6天

    #include <stdio.h>

    int main()

    {

        int x=100;

        if(x==0)

        {

            printf("x等于0 ");

            printf("x不等于1 ");

        }

        printf("程序结束 ");

        return 0;

    }

    输出程序结束

    #include <stdio.h>

    int main()

    {

        int x=100;

        if(x==100)

        {

            printf("x等于0 ");

            printf("x不等于1 ");

        }

        printf("程序结束 ");

        return 0;

    }

    输出全部的三条语句

    #include <stdio.h>

    int main()

    {

        int x=100;

        if(x==0);

        {

            printf("x等于0 ");

            printf("x不等于1 ");

        }

        printf("程序结束 ");

        return 0;

    }

    如果if(x==0)后面加了;例如这样if(x==0); ;代表一个语句的结束符,这样下面的语句都会执行

    #include <stdio.h>

    int main()

    {

        int x,y;

        printf("第一个数: ");

        scanf("%d",&x);

        printf("第二个数: ");

        scanf("%d",&y);

        if (x>y)

        {

            printf("第一个数比第二个数大。 ");

        }

        else

            printf("第二个数比第一个数大。 ");

        printf("程序结束 ");

        return 0;

    }

    scanf(“%d”,&x)要求输入一个整形,并赋值给x

    #include <stdio.h>

    int main()

    {

        float grade;

        printf("成绩: ");

        scanf("%f",&grade);

        if (grade<60)

        {

            printf("差。 ");

        }

        else if (grade<80)

        {

            printf("一般 ");

        }

        else if (grade<90)

        {

            printf("良好。 ");

        }

        else if (grade<100)

        {

            printf("优秀: ");

        }

        else

        printf("程序结束 ");

        return 0;

    }

    上面是if 加上else if

    #include <stdio.h>

    int main()

    {

        int x;

        printf("输入整数:");

        scanf("%d",&x);

        if(x>0)

        {

            if(x<100)

                printf("x大于0,小于100 ");

        }

        else

            printf("x小于等于0 ");

        return 0;

    }

    执行程序如果你输入大于0而且小于100的数,就会输出第一条语句,否则输出第二条语句

    #include <stdio.h>

    int main()

    {

        int x;

        printf("输入整数:");

        scanf("%d",&x);

        if(x>0)

            if(x<100)

                printf("x大于0,小于100 ");

        else

            printf("x小于等于0 ");

        return 0;

    }

    上面的函数去掉了中间的中括号{},因此下面的else与它最近的if配对,而不是与开头的if配对,这就是中括号{}的作用

     

  • 相关阅读:
    总结:工作 + 学习 (2019年)
    JVM 理解性学习(一)
    渗透神器cobalt strike在数字杀软环境下的使用
    普通路由器刷开源固件DD-WRT的简单过程
    云烟渗透题总结
    对thinkphp5.0框架的实例学习
    内网渗透 关于GPO
    简单尝试利用维控LeviStudioU的一栈缓冲区溢出漏洞
    试写foxit reader的ConvertToPDF功能的wrapper
    第05章下 加载内核
  • 原文地址:https://www.cnblogs.com/linuxboke/p/5610820.html
Copyright © 2011-2022 走看看