Пример 12
#include <cstdlib>
#include <iostream>
using namespace std;
int main()
{
int n, i, s = 0;
cout << "Please input n: ";
cin >> n;
for (i = 1; i <= n; i++)
s += i*i;
cout << "Sum of all positive numbers less or equal than n = " << s << endl;
cout << "(n*(n+1)(2n+1))/6 = " << (n*(n+1)*(2*n+1))/6 << endl;
system("PAUSE");
return EXIT_SUCCESS;
}
Задание 1, вариант 3
#include <cstdlib>
#include <iostream>
using namespace std;
int main()
{
int a1, b1, a2, b2;
cout << "Please input start position coordinates" << endl;
cout << "A = ";
cin >> a1;
cout << "B = ";
cin >> b1;
cout << "Please input end position coordinates" << endl;
cout << "A = ";
cin >> a2;
cout << "B = ";
cin >> b2;
if (a1 == a2 || b1 == b2)
{
cout << "Yes, you can reach end position in one move" << endl;
}
else
{
cout << "No, you can reach end position in one move" << endl;
}
system("PAUSE");
return EXIT_SUCCESS;
}
Задание 2, вариант 3
#include <cstdlib>
#include <iostream>
using namespace std;
int main()
{
int n, h, d, u;
for (int i = 10; i <100; i++)
{
n=i;
//h = i/100;
//cout << h << "-";
//n = i - h*100;
d = n/10;
//cout << d << "-";
u = n - d*10;
//cout << u << "-";
n = 2*d*u;
//cout << n << endl;
if (i == n)
cout << n << " ";
}
cout << endl;
system("PAUSE");
return EXIT_SUCCESS;
}
<== попередня сторінка |
| |
наступна сторінка ==> |
Пример 10 | | | | Переглядів: 309
Не знайшли потрібну інформацію? Скористайтесь пошуком google:
|
|