Вопрос про while(n-- > 0), что значит n-- > 0 ?? - C (СИ)
Формулировка задачи:
Ёлочка.
В циклах while условие n-->0, что оно обозначает??
#include <stdio.h>
#include <conio.h>
void print_triangle(int n, int shift)
{
int cnt, i, nblanks;
nblanks = 1 + (2 * (n-1)) / 2;
cnt = 1;
while (n-- > 0)
{
nblanks--;
for (i = 0; i < nblanks + shift; i++)
putchar(' ');
for (i = 0; i < cnt; i++)
putchar('*');
putchar('\n');
cnt += 2;
}
}
int main()
{
int n, i;
printf("enter a number of triangles: ");
scanf("%d", &n);
if (n < 0)
{
printf("invalid number!\n");
return 1;
}
i = 1;
while (n-- > 0)
print_triangle(++i, n);
getch();
return 0;
}Решение задачи: «Вопрос про while(n-- > 0), что значит n-- > 0 ??»
textual
Листинг программы
#include <iostream>
class Foo
{
public:
Foo(int foo = 0):
m_foo(foo)
{
}
int get_foo() const
{
return m_foo;
}
Foo operator--(int)
{
Foo temp = *this;
--m_foo;
return temp;
}
operator bool() const
{
return m_foo != 3;
}
private:
int m_foo;
};
bool operator>(const Foo& left, int right)
{
return left.get_foo() > right;
}
std::ostream& operator<<(std::ostream& stream, const Foo& foo)
{
return stream << foo.get_foo();
}
int main()
{
Foo a = 5, b = 5;
while (a-- > 0);
while (b--);
std::cout << a << std::endl << b << std::endl;
return 0;
}