結果

問題 No.1271 初めての級数
ユーザー kpinkcat
提出日時 2023-08-29 16:33:13
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 367 bytes
コンパイル時間 1,008 ms
コンパイル使用メモリ 98,792 KB
最終ジャッジ日時 2025-02-16 15:32:40
ジャッジサーバーID
(参考情報)
judge5 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 12 WA * 1
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:18:14: warning: ‘sum1’ may be used uninitialized [-Wmaybe-uninitialized]
   18 |         sum1 += 1./i;
      |         ~~~~~^~~~~~~
main.cpp:16:12: note: ‘sum1’ was declared here
   16 |     double sum1;
      |            ^~~~

ソースコード

diff #

#include<iostream>
#include<map>
#include<vector>
#include <algorithm>
#include<math.h>
#include <iomanip>
#include<set>
#include <numeric>
#include<string>
using namespace std;

int main()
{
    int k;
    cin >> k;
    double sum1;
    for (int i = 1; i <= k; i++){
        sum1 += 1./i;
    }
    cout << fixed << setprecision(8);
    cout << sum1/k << endl;
}   
0