// Возводит действилельное число x в целую степень n Procedure Pow(Const X:real; Const n:integer; Var St:real); Var i:integer; Begin St:=1; For i:= 1 to n do St:=St*x; End;
Var x,y,St:real; n:integer; Begin y:=0; Write('x = ');ReadLn(x); Write('n = ');ReadLn(n); For n:= 1 to n do Begin Pow(x,n,St); y:=y+Cos(St); End; WriteLn('y = ',y); End.
Функцией:
// Возводит действилельное число x в целую степень n Function Pow(Const X:real; Const n:integer):real; Var i:integer; Begin result:=1; For i:= 1 to n do result:=result*x; End; Var x,y:real; n:integer; Begin y:=0; Write('x = ');ReadLn(x); Write('n = ');ReadLn(n); For n:= 1 to n do y:=y+Cos(Pow(x,n)); WriteLn('y = ',y); End.
Циклом:
Var x,y,St:real; n:integer; Begin y:=0; Write('x = ');ReadLn(x); Write('n = ');ReadLn(n); St:=1; For n:= 1 to n do Begin St:=St*x; y:=y+Cos(St); End; WriteLn('y = ',y); End.
#include <map>
#include <string>
using namespace std;
int main()
{
string mon;
map<string, int> months = {
{"январь", 1},
{"февраль", 2},
{"март", 3},
{"апрель", 4},
{"май", 5},
{"июнь", 6},
{"июль", 7},
{"август", 8},
{"сентябрь", 9},
{"октябрь", 10},
{"ноябрь", 11},
{"декабрь", 12}
};
cout << "Введите название месяца строчными буквами: ";
cin >> mon;
switch (months[mon]) {
case 2:
cout << "28 дней";
break;
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
cout << "31 день";
break;
case 4:
case 6:
case 9:
case 11:
cout << "30 дней";
break;
}
cout << endl;
return 0;
}