int k, i = 1;
float c;
cout << "k="; cin >> k;
while (i <= k)
{
if (((int)pow(i, 2) + 1) / (i + 1) == 0)
cout << i << " ";
else
cout << "0 ";
i++;
}
return 0;
}
47. birikma son hisoblangan eng kichik n sonni toping (Serpinskiy masalasi).
48-misol. Matematikadan ma’lumki, n ning har qanday natural darajasi ketma-ket n ta toq natural sonlarning yig‘indisiga tengdir. n natural sonining har qanday darajasi uchun yig‘indisi ushbu darajaga teng bo‘lgan toq sonlar ketma-ketligini topuvchi dasturni tuzing.
{
int n, p, S, S1=0, j=1, i=1;
cout << "n="; cin >> n;
cout << "p="; cin >> p;
S =(int)pow(n, p);
cout << S << endl;
while (S!=S1)
{
while (i<=n)
{
S1 += j;
j += 2;
i++;
}
if (S == S1)
{
for (int l = 1; l <= n; l++)
{
j -= 2;
cout << j << "+";
}
break;
}
else
{
S1 = 0;
i = 1;
}
}
cout << "0=" << S << endl;
return 0;
}
49-misol. O‘nlik yozuvida ikkita bir xil raqam bo‘lmagan barcha to‘rt xonali sonlarni chop eting.
#include #include using namespace std;
int main()
{
int S;
for (int i = 0; i <= 9; i++)
for (int j = 0; j <= 9; j++)
for (int k = 0; k <= 9; k++)
for (int l = 0; l <= 9; l++)
if (i != j && i != k && i != l && j != k && j != l && k != l)
{
S = i * 1000 + j * 100 + k * 10 + l;
cout << S << endl;
}
}
50-misol. Har xil raqamlardan iborat 4 xonali sonni 9 ga ko‘paytirganda ko‘paytma shunday son bo‘ldiki, u ko‘paytuvchidan faqatgina minglar va yuzlar xonalaridagi raqamlar o‘rtasida 0 paydo bo‘lib qolganligi bilan farq qiladi. Ko‘paytiriluvchini toping.
#include #include using namespace std;
int main()
{
for (int i = 0; i <= 9; i++)
for (int j = 0; j <= 9; j++)
for (int k = 0; k <= 9; k++)
for (int l = 0; l <= 9; l++)
if (i != j && i != k && i != l && j != k && j != l && k != l)
{
if ((i * 1000 + j * 100 + k * 10 + l) * 9 == i * 10000 + j * 100 + k * 10 + l)
cout << i * 1000 + j * 100 + k * 10 + l << endl;
}
return 0;
}