A player will choose a number from the table and will replace that number with one of its divisor. For example, 6 can be replaced with 1, 2, or 3 (since these are the divisors of 6). Similarly, 12 can be replaced with 1, 2, 3, 4 or 6.
1
Expert's answer
2015-08-13T02:54:44-0400
#include <stdio.h>
int main() { int n; scanf("%i",&n); int ar[n]; for (int i=0;i<n;i++) scanf("%i",&ar[i]); for (int i=0;i<n;i++) printf("%i ",ar[i]); printf("\n"); for (int i=0;i<n;i++) printf("%i ",i); printf("\nWhat is your choice?\n"); int choice; scanf("%i",&choice); int a[ar[choice]]; int j=0; for (int i=1;i<n;i++) if (ar[choice]%i==0) { a[j]=i; j++; } printf("You can choose: "); for (int i=0;i<j;i++) printf("%i ",a[i]); printf("\n"); int replace; scanf("%i",&replace); ar[choice]=replace; for (int i=0;i<n;i++) printf("%i ",ar[i]);
Comments
Leave a comment