C语言写计算器,大学期末作业,课程设计

#include<stdio.h>
#include<math.h>
#include<Windows.h>
 
void Basic()
{
    int i;
    for (i = 1; i > 0; i++)
    {
        double a, b, c;
        int mode;
        system("cls");
        printf("加法(1)     减法(2)       乘法(3)      除法(4)     退出(5)\n");
        rewind(stdin);
        scanf_s("%d", &mode);
        if (mode == 5)
            break;
        else
        {
            switch (mode)
            {
            case 1: printf("Please Put Into Two Numbers:\n");
                scanf_s("%lf%lf", &a, &b);
                c = a + b;
                printf("%.3f\n", c);
                break;
            case 2: printf("Please Put Into Two Numbers:\n");
                scanf_s("%lf%lf", &a, &b);
                c = a - b;
                printf("%.3f\n", c);
                break;
            case 3: printf("Please Put Into Two Numbers:\n");
                scanf_s("%lf%lf", &a, &b);
                c = a * b;
                printf("%.3f\n", c);
                break;
            case 4: printf("Please Put Into Two Numbers:\n");
                scanf_s("%lf%lf", &a, &b);
                c = a / b;
                printf("%.3f\n", c);
                break;
            default: printf("输入有误"); break;
            }
        }
        system("pause");
    }
}
 
void Science()
{
    int i;
    for ( i = 1; i > 0; i++)
    {
        double a, b, c = 1, d, e, f, Average;
        int mode, j=0;
        system("cls");
        printf("正弦(1)   余弦(2)   正切(3)   指数(4)   对数(5)   阶乘(6)\n倒数(7)   平方(8)   立方(9)   方差{五个数}(10)    退出(11)\n");
        rewind(stdin);
        scanf_s("%d", &mode);
        if (mode == 11)
            break;
        else
        {
            switch (mode)
            {
            case 1:printf("Please Put Into The Number\n");
                scanf_s("%lf", &a);
                c = sin(a);
                printf("%f\n", c);
                break;
            case 2:printf("Please Put Into The Number\n");
                scanf_s("%lf", &a);
                c = cos(a);
                printf("%f\n", c);
                break;
            case 3:printf("Please Put Into The Number\n");
                scanf_s("%lf", &a);
                c = tan(a);
                printf("%f\n", c);
                break;
            case 4:printf("Please Put Into Two Numbers\n");
                printf("底数:");
                scanf_s("%lf", &a);
                printf("指数:");
                scanf_s("%lf", &b);
                c = pow(a, b);
                printf("%.1f", c);
                break;
            case 5:printf("Please Put Into Two Numbers\n");
                printf("底数:");
                scanf_s("%lf", &a);
                printf("真数:");
                scanf_s("%lf", &b);
                c = log10(b)/log10(a);
                printf("%.1f", c);
                break;
            case 6:printf("Please Put Into The Number\n");
                scanf_s("%lf",&a);
                while (j<a)
                {
                    c = c * (a - j);
                    j++;
                }
                printf("%.1f", c);
                break;
            case 7:printf("Please Put Into Two Numbers\n");
                printf("分子:");
                scanf_s("%lf", &a);
                printf("分母:");
                scanf_s("%lf", &b);
                d = a; a = b; b = d;
                c = a / b;
                printf("%.2f", c);
                break;
            case 8:printf("Please Put Into The Number\n");
                scanf_s("%lf", &a);
                c = pow(a, 2);
                printf("%.1f", c);
                break;
            case 9:printf("Please Put Into The Number\n");
                scanf_s("%lf", &a);
                c = pow(a, 3);
                printf("%.1f", c);
                break;
            case 10:printf("Please Put Into The Number\n");
                scanf_s("%lf%lf%lf%lf%lf", &a, &b, &c, &d, &e);
                Average = (a + b + c + d + e) / 5.0;
                f = (1.0 / 5) * ((a - Average) * (a - Average) + (b - Average) * (b - Average) + (c - Average) * (c - Average) + (d - Average) * (d - Average) + (e - Average) * (e - Average));
                printf("%.3f", f);
                break;
            default: printf("输入有误"); break;
            }
        }
        system("pause");
    }
}
 
 
 
int TurnNumber10_2(int a) {
    int c = 0, b = 1, d = 0;
    while (1) {
        d = a % 2;
        a = a / 2;
        c = c + d * b;
        b = b * 10;
        if (a < 2)
        {
            c = c + a * b;
            break;
        }
    }
 
    return c;
 
}
 
int TurnNumber8_10(int a)
{
        int i, b, c, d, sum = 0, j;
        for (j = 0; j >= 0; j++)
        {
            b = a / pow(10, j);
            if (b == 0)
            {
                break;
            }
        }
        for (i = 0; i < j; i++)
        {
            c = pow(10, i);
            d = (a / c) % 10;
            sum = sum + d*pow(8, i);
        }
    return sum;
}
 
int TurnNumber2_10(int a)
{
    int i, b, c, d, sum = 0, j;
    for (j = 0; j >=0 ; j++)
    {
        b = a / pow(10, j);
        if (b==0)
        {
            break;
        }
    }
    for (i = 0; i < j; i++)
    {
        c = pow(10, i);
        d = (a / c) % 10;
        sum = sum + d * pow(2, i);
    }
    return sum;
}
 
 
 
 
void Progrommer()
{
    int i;
    for (i = 1; i > 0; i++)
    {
        int a, b, c, j;
        int mode;
        system("cls");
        printf("十进制(1)     八进制(2)       二进制(3)      退出(4)\n");
        rewind(stdin);
        scanf_s("%d", &mode);
        if (mode == 4)
            break;
        else
        {
            switch (mode)
            {
            case 1:printf("Please Put Into The Number\n");
                scanf_s("%d", &a);
                printf("八进制=%o\n", a);
                printf("二进制=%d\n", TurnNumber10_2(a));
                break;
            case 2:printf("Please Put Into The Number\n");
                scanf_s("%d", &a);
                b = TurnNumber8_10(a);
                printf("十进制=%d\n", b);
                printf("二进制=%d\n", TurnNumber10_2(b));
                break;
            case 3:printf("Please Put Into The Number\n");
                scanf_s("%d", &a);
                b = TurnNumber2_10(a);
                printf("十进制=%d\n", b);
                printf("八进制=%o\n", b);
                break;
            default: printf("输入有误"); break;
            }
        }
        system("pause");
    }
}
 
 
int main()
{
    int i;
    for (i = 1; i > 0; i++)
    {
        rewind(stdin);
        int mode;
        printf("科学计算器\n");
        printf("普通模式(1)      科学模式(2)      程序员模式(3)     退出(4)\n");
        scanf_s("%d", &mode);
        if (mode == 4)
            break;
        else
        {
            switch (mode)
            {
            case 1: system("cls"); printf("普通模式\n"); Basic(); break;
            case 2: system("cls"); printf("科学模式\n"); Science(); break;
            case 3: system("cls"); printf("程序员模式\n"); Progrommer(); break;
            default: printf("输入有误"); break;
            }
        }
        system("cls");
    }
}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值