Ln Go

C++ 2중 for문 등차수열 합 출력 본문

c++

C++ 2중 for문 등차수열 합 출력

Ln Ro 2021. 5. 1. 14:34

#include <stdio.h>
#include <iostream>

using namespace std;
int main() 
{
        int sum = 0;
        int total = 0;
        int k = 0;

        for (int j = 1; j <= 10; j++) {
            for (int i = 1; i <= j; i++) {

                sum = sum + i;

            }
            cout << 1 << "~" << j << "까지의 합 : " << sum << endl;
            total = total + sum;
            sum = 0;

        }

        cout << "total=" << total;
}

 

'c++' 카테고리의 다른 글

vector 선언 3종류  (0) 2022.06.28
N Queen Algorithm  (0) 2022.02.24
c++ 문자열 대문자로 출력  (0) 2021.09.15
Online Compile Site  (0) 2021.06.03
비쥬얼 스튜디오 다운로드  (0) 2020.04.13
Comments