【学习日记】c语言 2022.8.2

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

#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>

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("%d\n", c);
    }


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

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

        int c = minus(a, b);

        printf("%d\n", c);
    }

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

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

        int c = multiply(a, b);

        printf("%d\n", c);
    }

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

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

        int c = divide(a, b);

        printf("%d\n", c);
    }

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

    scanf("%d", &f);

    }

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

    return 0;
}
 

总结:1.scanf后不加\n

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

           3.{}中可以套{}

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

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值