The following code runs a program in which the user must enter necessarily an even number, and then begins to decrease by 2 units go to number 2.
# include \u0026lt;iostream.h>
int a, b, c, d;
int main (void) {
court \u0026lt;\u0026lt;"Please enter an even number "\u0026lt;\u0026lt;endl \u0026lt;\u0026lt;endl;
cin>> a;
c = a% 2;
if (c == 0) {
d = a;
while (d> , 2) {
b = d-2;
d = b;
court \u0026lt;\u0026lt;(b) \u0026lt;\u0026lt;Endl;
}} else
{court \u0026lt;\u0026lt;"The number entered is even" \u0026lt;\u0026lt;endl \u0026lt;\u0026lt;endl;}
court \u0026lt;\u0026lt;"Many thanks for using this program "\u0026lt;\u0026lt;endl \u0026lt;\u0026lt;endl;
system (" pause ");
return 0;}
You may have noticed I use the operation MODULE to determine if the number is even or odd, and I use WHILE to write the series of numbers until just before get to number 2.
0 comments:
Post a Comment