chevron_left

メインカテゴリーを選択しなおす

cancel
大学生の雑記 https://coronene.hatenablog.com/

大学入試レベルの受験対策まとめや解説記事を書いています。 残りは雑記です。プログラミング系の記事の割合が多いです。

coronene
フォロー
住所
未設定
出身
未設定
ブログ村参加

2021/11/21

arrow_drop_down
  • コンソール上でボールを反射させる

    #include <iostream> #include <thread> #include <chrono> using namespace std; class Ball { public: int x, y; int width = 100; int height = 20; int d1 = 1; int d2 = 1; Ball(int startX, int startY) : x(startX), y(startY) {} void move() { x += d1; y += d2; if ((x > width) (x <= 0)) { d1 *= -1; } if (…

  • 台形公式で円周率を求める

    台形公式でガウス積分を計算し近似的に円周率を求めるプログラム。 #include<iostream> #include<iomanip> #include<math.h> using namespace std; //#define N 10 double f(double); int main() { cout << fixed << setprecision(15); // 小数点以下15桁を設定 double xs, xe, dx, result; int N = 100; xs = -10; xe = 10; result = 0; dx = (xe - xs) / N; for (i…

  • 【C++】N以下の素数を出力(平方根を使用)

    エラトステネスの篩を用いず、自然数の最大約数がになることを利用して2から以下の最大の整数までで一回ずつ割る方法を使用しました。 #include <iostream> using namespace std; int main() { int a = 100; for (int i = 2; i <= a; i++) { int p = 1; for (int j = 2; j <= sqrt(i); j++) { p *= (i % j); } if(p!=0){ //自身の平方根以下のどの自然数でも割り切れなかったとき cout << i << "\n"; } } return 0; }

  • 【C++】FizzBuzz

    #include <iostream> using namespace std; int main() { int i; for (i = 1; i <= 100; i++) { if (i % 15 == 0) { cout << i << " FizzBuzz" << "\n"; } else if (i % 5 == 0) { cout << i << " Buzz" << "\n"; } else if (i % 3 == 0) { cout << i << "Fizz" << "\n"; } } return 0; }

  • 【C++】フィボナッチ数列の計算プログラム

    C++の勉強のために簡単なプログラムを作ってブログにアウトプットしていきます。ただの記録用です。 第一回目はフィボナッチ数列の項を最初から計算していくものです。項比および黄金比と項比の差も同時に表示します。 #include <iostream> using namespace std; int main() { double a=0; double b = 1; double c = 1; int i = 0; double r; while (i < 10) { cout << "a= " << a << "\n"; c = b; b += a; a = c; r = b / a; i +…

arrow_drop_down

ブログリーダー」を活用して、coroneneさんをフォローしませんか?

ハンドル名
coroneneさん
ブログタイトル
大学生の雑記
フォロー
大学生の雑記

にほんブログ村 カテゴリー一覧

商用