728x90
1λ²
#include<iostream>
int main()
{
using namespace std;
cout << "λ κ°μ μ μ μ
λ ₯ : ";
int a, b, sum = 0;
cin >> a;
cin >> b;
for (int i = a; i <= b; i++)
sum += i;
cout << a << " λΆν° " << b << " κΉμ§μ ν©μ " << sum << endl;
return 0;
}
2λ²
#include<iostream>
#include<array>
const int ArSize = 101;
int main()
{
using namespace std;
array<long double, ArSize> factorials;
//long long factorials[ArSize];
factorials[1] = factorials[0] = 1L;
for (int i = 2; i < ArSize; i++)
factorials[i] = i * factorials[i - 1];
for (int i = 0; i < ArSize; i++)
std::cout << i << "! = " << factorials[i] << std::endl;
return 0;
}
3λ²
#include<iostream>
int main()
{
using namespace std;
int a,sum = 0;
do
{
cout << "μ μ
λ ₯ (0μ
λ ₯μ μ’
λ£) ";
cin >> a;
sum += a;
cout << "ν©κ³ : " << sum << endl;
} while (a != 0);
return 0;
}
4λ²
#include<iostream>
int main()
{
using namespace std;
double A=100000.0, B=100000.0;
int i = 1;
cout.setf(ios_base::fixed, ios_base::floatfield);
for (; A >= B; i++)
{
A +=100000*0.1;
B += 0.05*B;
cout << i << "λ
ν A μκΈ " << A << "\tB μκΈ " << B << endl;
}
cout << i - 1 << "λ
ν Bμ ν¬μ κ°μΉκ° Aμ ν¬μ κ°μΉλ₯Ό μ΄κ³Όν¨" << endl;
return 0;
}
728x90