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

}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS