PDA

View Full Version : C for loops


V|P
23 Jun 2007, 09:15am
How can I get the following results using only for loops and if-statements?

Number 1:

123454321
1234 4321
123 321
12 21
1 1

Number 2:
ABCDEDCBA
ABCD DCBA
ABC BCA
AB BA
A A

I just got a book on C and am learning it so this may be simple.

█Mike█
26 Jun 2007, 02:12pm
Well a hint i guess one can call it would be is to use characters. Notice for ascII in decimal '1' is 49, '2' is 50 and so on. That also goes for the letters 'A' is 65 and 'B' is 66. A for loop can increment up or down, so its a matter of number++; or number--;
Hope this helps,
Mike.