#include <iostream>
#include <cmath>
using namespace std;
int main() {
float a(-1),b(1),h,x1,x2,y1,y2,k,s(0);
int n(2);
do {
k=s; s=0;
for (int j=1; j<=n; j++) {
h=(b-a)/n;
x1=a+h*(j-1); x2=x1+h;
y1=x1*x1; y2=x2*x2;
s=s+(y1*h+y2*h)/2;
}
n++;
if (abs(s-k)<0.01) {
cout << "1" << endl;
break;
}
}
while(n>=0);
cout << s <<endl << n << endl;
return(0);
}
Напишем программу, которая будет считать сумму всех чисел от 1 до 1000.
<span><span>#include <iostream>
</span>
using namespace std;<span>
int main()
</span>{
int i; // счетчик цикла
int sum = 0; //сумма чисел от 1 до 1000.
setlocale(0, "");
for (i = 1; i <= 1000; i++) // задаем начальное значение 1, конечное 1000 и задаем шаг цикла - 1.
{
sum = sum + i;
}
cout << "Сумма чисел от 1 до 1000 = " << sum <<
endl;
return 0;
}</span>
#include <iostream>
using namespace std;
int main() {
<span> int a;
cin >> a;
if (a==3)
{
cout << "Win";
}
else </span>if (a==0)
{
cout << "Defeat";
}
else if (a==1)
{
cout << "Draw";
}
else cout << "Unknown";
<span> return 0;
</span>}
1.
#include <iostream>
using namespace std;
int main(){
int n, p;
cin >> n;
int a[n];
for(int i = 0; i!=n; i++)
cin >> a[i];
for(int i = 0; i!=n; i++)
cout << a[i] << " ";
cout << endl << "Введите число k ";
cin >> p;
for(int i = 0; i!=n; i++)
if(a[i]>p)
cout << a[i];
return 0;
}
2.
#include <iostream>
using namespace std;
int main(){
int n, sum = 0;
cin >> n;
int a[n];
for(int i = 0; i!=n ;i++){
cin >> a[i];
sum = sum + a[i];
}
for(int i = 0; i!=n ;i++)
cout << a[i] << " ";
cout << endl << sum;
return 0;
}