Пример 10
#include <cstdlib>
#include <iostream>
using namespace std;
int main()
{
int n; // input
int s = 0;
do
{
cout << "Please enter an integer: ";
cin >> n;
if (n<0)
{
s = s + n*n;
}
}
while (n != 0);
cout << "Sum of kvadrati of inputed negative numbers is = " << s << endl;
system("PAUSE");
return EXIT_SUCCESS;
}
Пример 11
#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 = s + i;
}
cout << "Sum of all positive numbers less or equal than n = " << s << endl;
cout << "n*(n+1)/2 = " << n*(n+1)/2 << endl;
system("PAUSE");
return EXIT_SUCCESS;
}
Не знайшли потрібну інформацію? Скористайтесь пошуком google:
|
|