栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

【学习日记】 c语言 2022.8.2

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

【学习日记】 c语言 2022.8.2

学习c语言第4天,完全自己写的第一串代码

#define _CRT_SECURE_NO_WARNINGS

#include

add(int a,int b)
{
    int c = a + b;

    return c;
}

minus(int a,int b)
{
    int c = a - b;

    return c;
}

multiply(int a,int b)
{
    int c = a * b;

    return c;
}

divide(int a, int b)
{
    int c = a/b;

    return c;
}

int main()
{
    int f = 1;

    while(f>0)
    {
    int select = 0;

    int a, b, c = 0;
    
    printf("欢迎使用计算器,加法请按0,减法请按1,乘法请按2,除法(仅能保留到整数)请按3(0/1/2/3)>:");

    scanf("%d", &select);

    if (select == 0)
    {
        printf("请填入两个需要相加的数,中间加空格n");

        scanf("%d %d", &a, &b);

        int c = add(a, b);

        printf("%dn", c);
    }


    if (select == 1)
    {
        printf("请填入两个需要相减的数,中间加空格n");

        scanf("%d %d", &a, &b);

        int c = minus(a, b);

        printf("%dn", c);
    }

    if (select == 2)
    {
        printf("请填入两个需要相乘的数,中间加空格n");

        scanf("%d %d", &a, &b);

        int c = multiply(a, b);

        printf("%dn", c);
    }

    if (select == 3)
    {
        printf("请填入两个需要相除的数,中间加空格,除法仅能保留到整数n");

        scanf("%d %d", &a, &b);

        int c = divide(a, b);

        printf("%dn", c);
    }

    printf("需要继续吗,需要请按1,不需要请按0(0/1)>:");

    scanf("%d", &f);

    }

        printf("感谢您的使用n");

    return 0;
}
 

总结:1.scanf后不加n

           2.c语言除法保留到整数

           3.{}中可以套{}

           4.别忘加"" () ;  细心极为重要

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/1034703.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号