main
int
in your programs
int x, y;
C++ | Meaning |
---|---|
< | less than |
<= | less than or equal to |
> | greater than |
>= | greater than or equal to |
== | equals |
!= | not equals |
// r is the remainder of x / y r = x % y; cout << 5 % 2; // 1 cout << 2 % 5; // 2
if (a < 10) { b = 2; } else { b = 10; } |
if (a < 10) { b = 2; } |
c = 1; while (c <= 5) { cout << c; c = c + 1; } |
c = 1; do { cout << c; c = c + 1; } while (c <= 5); |
if (x <= y) { cout << x; x = x - 1; } |
Show/hide solution
#include <iostream> using namespace std; void main() { int n, t, d; cout << "Enter a number: "; cin >> n; t = 0; d = 1; while (d <= n/2) { if (n % d == 0) { t = t + d; } d = d + 1; } if (t == n) { cout << n << " is perfect."; } else { cout << n << " is NOT perfect."; } } |