19.06.2012, 23:11
A question like this was on my ICT exams,
So I was being bored at home and made something real quick.
Example:
/loop 2 5 would give:
2 + 0 = 2
2 + 1 = 3
3 + 2 = 5
5 + 3 = 8
8 + 4 = 12
12 + 5 = 17
P would be 17 at the end of this loop.
that's basically what I do when I'm bored
Quote:
In a loop like shown above, what would p be at the end? |
pawn Код:
CMD:loop(playerid, params[])
{
new p;
new a;
new piet;
if(sscanf(params, "ii", p,a)) return SCM(playerid, COLOR_GREY, "USAGE: /loop [1-50] [1-15]");
if(a < 0 || a > 15) return SCM(playerid, COLOR_GREY, "USAGE: /loop [1-50] [1-15]");
if(p < 0 || p > 50) return SCM(playerid, COLOR_GREY, "USAGE: /loop [1-50] [1-15]");
piet = p;
for(new i = 0; i <= a; i++)
{
p = p + i;
}
new string[128];
format(string, sizeof(string), "[DEBUG] Using Starting number %d and loop size %d the result would be %d", piet, a, p);
print(string);
printf("[DEBUG] Set P %d,Set A %d ||==||==|| P = P + A gives P = %d while loop = A", piet, a, p);
SCM(playerid, COLOR_WHITE, string);
return 1;
}
Example:
/loop 2 5 would give:
2 + 0 = 2
2 + 1 = 3
3 + 2 = 5
5 + 3 = 8
8 + 4 = 12
12 + 5 = 17
P would be 17 at the end of this loop.
that's basically what I do when I'm bored