LoginSignup
0
0

More than 5 years have passed since last update.

C言語での計算機のソースコード

Last updated at Posted at 2017-08-11

 こんにちはThe SOLARです。

 今回は、C言語での計算機のソースコードを配布します。
 
 このプログラムは、四則演算だけでなく、
 四角形の面積、三角形の面積も求められます。

#include <stdio.h>

int main(void)
{
        int tate;
        int yoko;
        int kekka;
        int nyuu;
        int bosuu;
        int shisuu;

        START:

        printf_s("1で三角形の面積 2で四角形の面積\n");
        printf_s("3で足し算 4で引き算 5で掛け算 6で割り算\n");

        scanf_s("%d", &nyuu);

        switch (nyuu)
        {
        case 1:
        case 2:
                goto zukei;
        case 3:
        case 4:
        case 5:
        case 6:
                goto keisan;
        default:
                goto START;
        }

zukei:

        printf_s("横の長さを入力してください\n");

        scanf_s("%d", &yoko);

        printf_s("縦の長さを入力してください\n");

        scanf_s("%d", &tate);

<<<<<<< HEAD
    switch (nyuu)
    {
    case 1:
        printf_s("%d * %d / 2 = %d\n", yoko, tate, kekka = yoko * tate / 2);
        goto START;
    case 2:
        printf_s("%d * %d = %d\n", yoko, tate, kekka = yoko * tate);
        goto START;
    default:
        break;
    }
=======
        switch (nyuu)
        {
        case 1:
                printf_s("%d * %d / 2 = %d\n", yoko, tate, nyuu = yoko * tate / 2);
                goto START;
        case 2:
                printf_s("%d * %d = %d\n", yoko, tate, kekka = yoko * tate);
                goto START;
        default:
                break;
        }
>>>>>>> EDIT_REQUEST

keisan:

        printf_s("最初の数を入力してください\n");

        scanf_s("%d", &bosuu);

        printf_s("次の数を入力してください\n");

        scanf_s("%d", &shisuu);

        switch (nyuu)
        {
        case 3:
                printf_s("%d + %d = %d\n", bosuu, shisuu, kekka = bosuu + shisuu);
                goto START;
        case 4:
                printf_s("%d - %d = %d\n", bosuu, shisuu, kekka = bosuu - shisuu);
                goto START;
        case 5:
                printf_s("%d * %d = %d\n", bosuu, shisuu, kekka = bosuu * shisuu);
                goto START;
        case 6:
                printf_s("%d / %d = %d\n", bosuu, shisuu, kekka = bosuu / shisuu);
                goto START;
        default:
                goto START;
        }

        return 0;
}
0
0
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0