How Can I Use A Scanf to alter combinations?
Write a program that prompts the user for a five digit lab access code, read it in as an unsigned integer then print to the screen each of the five digit access codes (with possible leading zeroes) that are equivalent (there are 32). Be aware that 1 and 2 are on the same button, as are 3 and 4, etc. 9 and 0 are on the same button, as well. The picture below is an example of a key access device that has 0 and 1 on the first button, 2 and 3 on the next button and so on.
0|_|{1,2}
1|_|{3,4}
2|_|{5,6}
3|_|{7,8}
4|_|{9,0}
#include <stdio.h>
int main(void) {
#define foreach( intpvar, intary ) int* intpvar; for( intpvar=intary; intpvar < (intary + (sizeof(intary)/sizeof(intary[0]))) ; intpvar++)
int a1[]={1,2};
int a2[]={3,4};
int a3[]={5,6};
int a4[]={7,8};
int a5[]={9,0};
foreach (p1, a1) {
foreach (p2, a2) {
foreach (p3, a3) {
foreach (p4, a4) {
foreach (p5, a5) {
printf("%d %d %d %d %d\n",*p1,*p2,*p3,*p4, *p5);
}
}
}
}
}
return 0;
}