两个吃奶一个添下面视频_人妻第一页香蕉网_欧美xxxx少妇_妺妺窝人体色www婷婷

一、項目介紹

C語言版簡易計算器,包含幾個小功能,包括基本運算、進制轉換、一元二次方程,支持返回操作,整體源碼比較精簡,代碼邏輯簡單,擴展性強,非常適合新手了解和學習的小項目。


二、運行截圖

導航菜單,支持六種計算(可擴展)

計算器-菜單

根據(jù)輸入選擇,可重復使用

計算器-運算

        階乘計算

計算器-進制轉換

三、代碼思路

代碼整體依靠一個swtich結構根據(jù)用戶的輸入做分支,分別調(diào)用對應的計算函數(shù),由于代碼比較短,將每個計算的代碼分別寫到了每個case里,代碼邏輯簡單,核心計算都是套數(shù)學公式即可,沒有什么難度,大家可以直接讀代碼,并有參考注釋。


建議:大家可以根據(jù)情況予以功能增加,然后將獨立的代碼封裝到函數(shù)里,體會函數(shù)模塊化思想,讓代碼更簡潔。


四、完整源碼

#include <stdio.h> 
#include <math.h> 
#include <stdlib.h> 
//預處理指令
int main(void)
{
        double bNumber, Number, Result;                //給加減乘除定義的變量
        int No;                //選項的定義變量
        double a, b, c, x1, x2, Rad;                //給一元一次方程定義的變量
        int Ary_10;                                        //定義進制的變量
        char string[32];                //二進制變量定義
        system ("title: www.sztianhecheng.cn");
        while(1)
        {
                //界面
                printf ("┏ ┅ ┅ ┅ ┅ ┅ ┅ ┅ ┅ ┅ ┅ ┅ ┅ ┅ ┅ ┅ ┓\n");
                printf ("┇請選擇你要計算的方法:                         ┇\n");
                printf ("┣ ┅ ┅ ┅ ┅ ┅ ┅ ┅ ┅ ┅ ┅ ┅ ┅ ┅ ┅ ┅ ┫\n");
                printf ("┇  加法請按_1    進制轉換_5                    ┇\n");
                printf ("┇  減法請按_2    求一元二次方程_6              ┇\n");
                printf ("┇  乘法請按_3                                  ┇\n");
                printf ("┇  除法請按_4               退出_0             ┇\n");
                printf ("┗ ┅ ┅ ┅ ┅ ┅ ┅ ┅ ┅ ┅ ┅ ┅ ┅ ┅ ┅ ┅ ┛\n");
                printf ("Please write down the number:");
                scanf ("%d",&No);
                if (No == 1)
                {
                        //        加法
                        printf ("        請輸入被加數(shù):");
                        scanf ("%lf",&bNumber);
                        printf ("        請輸入加數(shù):");
                        scanf ("%lf",&Number);
                        Result = bNumber + Number;
                        printf (" 結果是: %lf\n\n",Result);
                }
                else if (No == 2)
                {
                        //        減法
                        printf ("        請輸入被減數(shù):");
                        scanf ("%lf",&bNumber);
                        printf ("        請輸入減數(shù):");
                        scanf ("%lf",&Number);
                        Result = bNumber - Number;
                        printf (" 結果是: %lf\n\n",Result);
                }
                else if (No == 3)
                {
                        //        乘法
                        printf ("        請輸入被乘數(shù):");
                        scanf ("%lf",&bNumber);
                        printf ("        請輸入乘數(shù):");
                        scanf ("%lf",&Number);
                        Result = bNumber * Number;
                        printf (" 結果是: %lf\n\n",Result);
                }
                else if (No == 4)
                {
                        //        除法
                        printf ("        請輸入被除數(shù):");
                        scanf ("%lf",&bNumber);
                        printf ("        請輸入除數(shù):");
                        scanf ("%lf",&Number);
                        Result = bNumber / Number;
                        printf (" 結果是: %lf\n\n",Result);
                }
                else if (No == 5)
                {
                        //進制轉換的代碼
                        printf("請輸入需要轉換的十進制數(shù):");
                        scanf("%d", &Ary_10);
                        itoa (Ary_10, string ,2);
                        printf("二進制: %s\n", string);
                        printf("八進制: %o\n", Ary_10);
                        printf("十六進制: %x\n", Ary_10);
                }
                else if (No == 6)
                {
                        //求一元二次方程的解的代碼
                        printf("請輸入一元一次方程的a,b,c三個數(shù):");
                        scanf("%lf%lf%lf",&a,&b,&c);
                        Rad = b*b - 4*a*c;
                        if (Rad > 0)
                        {
                                x1 = -b + sqrt(Rad) / (2*a);
                                x2 = -b - sqrt(Rad) / (2*a);
                                printf("有兩個解 x1 = %lf, x2 = %lf\n", &x1, &x2);
                        }
                        else if (Rad == 0)
                        {
                                x1 = -b / (2*a);
                                printf("只有一個解 x1 = %lf\n", &x1);
                        }
                        else
                        {
                                printf("無解\n");
                        }
                }
                else if (No == 0)
                {
                        //        退出程序
                        break;
                }
                else
                {
                        //        輸入的選項不對
                        printf("  請輸入正確的數(shù)字。\n\n");
                }
                system ("pause");        //按任意鍵繼續(xù)
                system ("cls");                //清屏
        }
        return 0;
        getchar();
}


點贊(0)

C語言網(wǎng)提供由在職研發(fā)工程師或ACM藍橋杯競賽優(yōu)秀選手錄制的視頻教程,并配有習題和答疑,點擊了解:

一點編程也不會寫的:零基礎C語言學練課程

解決困擾你多年的C語言疑難雜癥特性的C語言進階課程

從零到寫出一個爬蟲的Python編程課程

只會語法寫不出代碼?手把手帶你寫100個編程真題的編程百練課程

信息學奧賽或C++選手的 必學C++課程

藍橋杯ACM、信息學奧賽的必學課程:算法競賽課入門課程

手把手講解近五年真題的藍橋杯輔導課程

Dotcpp在線編譯      (登錄可減少運行等待時間)