User:Laurier Rochon/prototyping/triple loops
< User:Laurier Rochon
Revision as of 21:36, 3 November 2010 by Laurier Rochon (talk | contribs) (Created page with "'''Getting the dual channel shift in C, using a WHILE or a FOR loop''' Solution 1 : while loop + no modulo <source lang="C"> #include "stdio.h" int pat[]={1,1,1,0,1,1,0,1,0,1,...")
Getting the dual channel shift in C, using a WHILE or a FOR loop
Solution 1 : while loop + no modulo
#include "stdio.h"
int pat[]={1,1,1,0,1,1,0,1,0,1,1,0};
int main (){
int len=sizeof(pat)/sizeof(int);
int shifter=0;
int i=0;
int outer=0;
int temp=0;
for(outer=0; outer<len; outer++){
for(shifter=0; shifter<len; shifter++){
for(i=0; i<len; i++){
temp = shifter+i;
if(temp>len-1) temp-=len;
printf("%d",pat[i]);
printf(" ");
printf("%d",pat[temp]);
printf(" ");
printf("(%d)",i);
printf("\n");
}
printf("- - - %d\n",(outer+1));
}
}
}
Solution 2 : for loop + modulo
#include "stdio.h"
int pat[]={1,1,1,0,1,1,0,1,0,1,1,0};
int main (){
int len=sizeof(pat)/sizeof(int);
int shifter=0;
int i=0;
int outer=0;
int temp=0;
for(shifter=0; shifter<len; shifter++){
for(outer=0; outer<len; outer++){
for(i=0; i<len; i++){
printf("%d",pat[i]);
printf(" ");
printf("%d",pat[((shifter+i)%12)]);
printf("\n");
}
printf("- - -\n");
}
}
}