Cyclic Permutation in C: Create Alphabet Pattern with Nested For Loops

  • Thread starter Thread starter TheSourceCode
  • Start date Start date
  • Tags Tags
    Cyclic Permutation
Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
2 replies · 3K views
TheSourceCode
Messages
14
Reaction score
0
Use nested for loops to produce the following pattern of cyclic permutations of the English
alphabet:
abcde...yz
bcdef...za
cdef...zab
...
zabcde...xy
HINT: you may find the modulo (remainder) operator % useful.

I have an idea of how to do this but it would not use the modulo operator. I thought of saving the first letter of an array into a variable, shifting everything else down one and putting it at the end. This also would only implement a single for loop. Any clues would be greatly appreciated.
 
Physics news on Phys.org
Yes, there are probably a million ways to do this, but I suggest that you have one loop generating the first character of each string and an inner loop (since that what was asked for) generating the successive letters of each string - using modulo operator to make the wrap from z to a.
 
Thanks a lot. Took me a bit to get the wrap around to work properly but I got it. I don't think modulo was very intuitive to me before but now I get it.