C/C++

Скоро сдача, а я не успеваю всё сделать, помогите. Прошу вас... С/С++

1) S= 1+ 2 + 3+...+117; (s=6903)
2) S= sin1 + sin 2 +..+ sin25; (s=-0.058)
3) S= tg2 + tg4 +..+ tg(N*2); N = ввести с клавиатуры (при N=19
S=1)
4) S= ln 0.1 + ln 0.3 +..+ ln1.9 (s=-2.726)
AA
Aibat Abylov
105
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
void show(int x, const char* msg = "s: ") {
cout << msg << x << '\n';
}
unsigned integer(const char* msg) {
cout << msg;
unsigned value;
cin >> value;
cin.ignore(cin.rdbuf()->in_avail());
return value;
}
void show(double x, streamsize w = 15, const char* msg = "s: ") {
cout << fixed << setprecision(w) << msg << x << '\n';
}
int sum_a(unsigned n) {
return n * (n + 1) >> 1;
}
double sum_b(unsigned n, double s = 0.0) {
s += sin(n);
return n? sum_b(n - 1, s) : s;
}
double sum_c(unsigned n, double s = 0.0) {
s += tan(n << 1);
return n? sum_c(n - 1, s) : s;
}
double sum_d(int n) {
static auto tmp = 0.0;
if (n < 1) {
auto sum = tmp;
tmp = 0.0;
return sum;
}
tmp += log(n / 10.0);
return sum_d(n - 2);
}
int main() {
auto a = sum_a(117);
show(a);
auto b = sum_b(25);
show(b, 3);
auto n = integer("N: ");
auto c = sum_c(n);
show(c, 2);
auto d = sum_d(19);
show(d, 3);
system("pause > nul");
}
ГР
Геннадий Романцевич
61 070
Лучший ответ
9
18
56
7.34
Aibat Abylov Спасибо, но боюсь препод не оценит )
Павел Гладышев Тогда оцени его ты, за пределами ВУЗа ))))
#include
void main(){ int i=0; int s=0; while( i++ < 117 ) s+=i; printf("%d",s); }