# Answer to Question #54038 in C for mallika

Question #54038

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.

Expert's answer

#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]);

}

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