Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Program in C++. you have number 123456789. find the permutations so that the lef

ID: 3748282 • Letter: P

Question

Program in C++. you have number 123456789. find the permutations so that the left most digit is evenly divisible by 1, the 2 left digits are evenly divisible by 2 and 3 left most digits are divisble by 3 etc. for example 1234 is not evenly divisible by 4 so it's not a solution. the program needs to have up to 5 digits ranging from 1-9, each with a count of how many answers there are. for example: for 1 digit there are 9 answers. program in c++ and show picture of output

show how to make program eliminate numbers to that you know for sure are wrong ( for example 1223 is not a solution for 4 digits because digits aren't unique.)

Explanation / Answer

#include <stdio.h>
void combn(int arrayy[], int info[], int strt, int endd,  
int indx, int r);
void printCombination(int arrayy[], int n, int r)
{
int info[r];
combn(arrayy, info, 0, n-1, 0, r);
}
void combn(int arrayy[], int info[], int strt, int endd,
int indx, int r)
{
if (indx == r)
{
for (int j=0; j<r; j++)
printf("%d ", info[j]);
printf(" ");
return;
}
for (int i=strt; i<=endd && endd-i+1 >= r-indx; i++)
{
info[indx] = arrayy[i];
combn(arrayy, info, i+1, endd, indx+1, r);
}
}
int main()
{
int arrayy[] = {1, 2, 3, 4, 5};
int r = 3;
int n = sizeof(arrayy)/sizeof(arrayy[0]);
printCombination(arrayy, n, r);
}

Dr Jack
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote