zoukankan      html  css  js  c++  java
  • 大四中软实习笔记20130225

    1 C语言的概述
    1.1 为什么要学习高级语言
    机器语言----汇编语言----高级语言

    程序员:
    先将任务 用汉语表达清楚
    将汉语翻译成C语言

    2 学习C语言-----外语
    2.1 怎么学
    学习 字、词:
    2.1.1 四大基本数据类型
    int                4个字节            大致范围+-20亿           
    char            1个                    'a'  'b'  'c' '1'  '2'  '3' '\1'  '\4'  '\n'  '\t'   ASCII码
    float            4个                    10^100
    double        8个                    10^1000

    2.1.2 句子
    一、顺序语句:
    例子:
    求和运算
    代码:
    #include <stdio.h>
    int main()
    {
        int a=10;
        int b=20;
        int c=a+b;
        printf("%d\n",c);
        return 0;
    }

    二、分支语句
    if()
    {

    }
    else
    {

    }
    题目:输入2个数a,b,当a>b时,输出a的值;否则,输出b的值。
    代码:
    #include <stdio.h>
    int main()
    {
        int a;
        int b;
        int result;
        printf("请输入第1个整型数:");
        scanf("%d",&a);
        printf("请输入第2个整型数:");
        scanf("%d",&b);
        if(a>b)
        {
            result=a;
        }
        else
        {
            result=b;
        }
        printf("%d和%d的最大值是%d\n",a,b,result);

        return 0;
    }


    switch()
    {
    case:

    case:

    default:

    }
    题目:输入1个数学成绩,当成绩大于等于90分时,打印优秀;大于等于80,打印良;大于等于60,大于及格;否则,不及格;
    代码:
    #include <stdio.h>
    int main()
    {
        int math;
        int flag;
        printf("请输入1个数学成绩:");
        scanf("%d",&math);
        flag=math/10;
        switch(flag)
        {
        case 10:
            printf("满分\n");
            break;
        case 9:
            printf("优秀\n");
            break;
        case 8:
            //printf("良\n");
            //break;
        case 7:
            printf("良\n");
            break;
        case 6:
            printf("及格\n");
            break;
        default:
            printf("不及格\n");
            break;   
        }

        return 0;
    }

    注意点:
    1、break不能漏
    2、case后面必须是常量,如整型常量、字符型常量( 'a' )、枚举型
    3、scanf一定要用最简的办法。也就是不要用 , \n    &不能漏

    三、循环
    while(条件)
    {

    }
    题目:输入1个数学成绩,当成绩大于等于90分时,打印优秀;大于等于80,打印良;大于等于60,大于及格;否则,不及格;并且可以循环输入和打印结果,直到输入10000时,退出循环
    代码:
    #include <stdio.h>
    int main()
    {
        int math;
        int flag;
       
        while(1)
        {   
            printf("请输入1个数学成绩:");
            scanf("%d",&math);
            flag=math/10;
            switch(flag)
            {
            case 1000:
                break;
            case 10:
                printf("满分\n");
                break;
            case 9:
                printf("优秀\n");
                break;
            case 8:
                //printf("良\n");
                //break;
            case 7:
                printf("良\n");
                break;
            case 6:
                printf("及格\n");
                break;
            default:
                printf("不及格\n");
                break;   
            }
            if(flag==1000)
            {
                break;
            }
            else
            {
                ;
            }
               
        }
       
        return 0;
    }


    作业:输入2个数a,b,当输入+时,返回和;当输入-时,返回差,当输入*,返回积;当输入/时,返回商;可以循环计算,直到输入q时,退出。

    知识点:

    1.解决scanf输入字符时,自动跳过键盘输入的问题:

    getchar();     //'\n'

    fflush(stdin); //stddin代表输入设备如键盘;

    break跳出一层循环

  • 相关阅读:
    Security and Cryptography in Python
    Security and Cryptography in Python
    Security and Cryptography in Python
    Security and Cryptography in Python
    Security and Cryptography in Python
    Security and Cryptography in Python
    基于分布式锁解决定时任务重复问题
    基于Redis的Setnx实现分布式锁
    基于数据库悲观锁的分布式锁
    使用锁解决电商中的超卖
  • 原文地址:https://www.cnblogs.com/blueswitkey/p/2933008.html
Copyright © 2011-2022 走看看