Var N,i:integer; s:real;beginwriteln('vvedite N');readln(N);s:=1;for i:=2 to N dos:=s-1/i;writeln('Summa = ',s);end.
Если все внимательно слушали на уроке, то так или иначе сделают домашнее задание.
#include <iostream>
using namespace std;
struct link
{
double data;
link* next;
};
link* first = NULL;
void additem(int d) // добавление элементов список
{
link* newlink = new link;
newlink->data = d;
newlink->next = first;
first = newlink;
}
void display() // вывод на экран
{
link* current = first;
while(current)
{
cout << current->data << " ";
current = current->next;
}
}
int max() // max
{
link* current = first;
int m=0;
while(current)
{
if (current->data > m) m = current->data;
current = current->next;
}
return m;
}
void norm(int m) // нормализация
{
link* current = first;
while(current)
{
current->data /= m;
current = current->next;
}
}
int main()
{
int n=10;
int a;
for (int i=1; i<n; i++) {
cin >> a;
additem(a);
}
display();
cout << endl << max() << endl;
norm(max());
display();
}
Пример:
<span>64 45 19 42 83 38 71 23 52
83
0.771084 0.542169 0.228916 0.506024 1 0.457831 0.855422 0.277108 0.626506 </span>