President gets advice from his pool of advisers every time he needs to make a decision. He has 13 top advisers that he really relies on. But if all of them are involved in any decision, they always end up in an argument where more often than not, the final decision is not achieved. To resolve this, a scheme was devised where only 5 of the 13 will be randomly chosen to decide on a certain matter.

They achieved this by having the 13 advisers arrange themselves in a circle. The President can start counting from a certain adviser with an appropriate counting interval. For example, he can start counting from adviser 1 with a counting interval of 4. Then the first adviser counter out will be adviser 4, followed by advisers 8, 12, 3 and 9. Note that those advisers who are already counted out will not be counted again.

Write a program that would ask which adviser to start from and ask the counting interval. Then, it should display which advisers were selected.

Here's my code...

Code:

#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
struct bla
{
int num;
int status;
} advisor[13];
int check(int x[5])
{
int lp1 = 0, lp2 = 0;
while(lp1 != 5)
{
if(x[lp1] > 0)
{
lp2++;
}
lp1++;
}
if(lp2 == 5)
{
return 1;
}
else
{
return 0;
}
}
void main()
{
int lp1 = 0, lp2 = 0, lp3 = 0;
int start = 0, interval = 0, ch = 0;
int chosen[5] = {0, 0, 0, 0, 0};
clrscr();
printf("Start: ");
scanf("%d", &start);
if(start == 0)
{
exit(1);
}
printf("Interval: ");
scanf("%d", &interval);
lp2 = start - 1;
for(lp1 = 1; lp1 <= 13; lp1++)
{
advisor[lp1].num = lp1;
advisor[lp1].status = 1;
}
while(ch != 1)
{
if(advisor[lp2].status == 1)
{
lp3++;
if(advisor[lp2].num == interval)
{
advisor[lp2].status = 0;
chosen[lp1] = advisor[lp2].num;
lp1++;
}
if(lp3 == interval)
{
chosen[lp1] = advisor[lp2].num;
advisor[lp2].status = 0;
lp1++;
lp3 = 0;
}
}
lp2++;
if(lp2 == 13)
{
lp2 = 0;
}
ch = check(chosen);
printf("%d ", ch);
}
for(lp1 = 0; lp1 < 5; lp1++)
{
printf("\nChosen Adviser %d: %d", lp1+1, chosen[lp1]);
}
getch();
}