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

Exercise 8. The goal of this exercise is to find the number of integer solutions

ID: 3911873 • Letter: E

Question

Exercise 8. The goal of this exercise is to find the number of integer solutions of the equation x1 + x2 + x3 + x4 = 12 such that xi ? 0, i = 1, 2, 3 and 4. Suppose that you have 12 marbles to place in 4 boxes (x1 is the number of marbles put in box 1, x2 is the number of marbles put in box 2,...). One way to do this is, as shown in the picture, x1 = 1,x2 = 3, x3 = 4 and x4 = 4

Now, if we denote the marbles of the picture by zeros delimited by ones in a bit string of length 15 , we get: 0 1 000 1 0000 1 0000

Use your solution of Exercise 7 to solve the equation x1 + x2 + x3 + x4 = 12 where xi ? N ? {0}

Exercise 9. How many integer solutions of the equation x1 + x2 + x3 = 12 such that xi ? 1, ?i ? {1, 2, 3}.

Explanation / Answer

/*if you want DISTINCT solutions then you can check the following

and since there are 4 variables..there are 4! ways of arranging each solution.

so number of required solutions is C*(4!).*/

#include<stdio.h>

main()

{

int i,j,k,l,c=0;

for(i=0;i<=12;i++)

{

for(j=i+1;j<=12;j++)

{

for(k=j+1;k<=12;k++)

{

for(l=k+1;l<=12;l++)

{

if((i+j+k+l)==12)//the required equation

{

c++;

printf("%d %d %d %d ",i,j,k,l);

}

}

}

}

}

printf("the number of solutions : %d",c);//number of solutions

}

/*YOU can try this also to get total number of solutions with same numbers also..

for example...((9+1+1+1)=12)or ((12+0+0+0)=12)*/

#include<stdio.h>

main()

{

int i,j,k,l,c=0;

for(i=0;i<=12;i++)

{

for(j=0;j<=12;j++)

{

for(k=0;k<=12;k++)

{

for(l=0;l<=12;l++)

{

if((i+j+k+l)==12)//the required equation

{

c++;

printf("%d %d %d %d ",i,j,k,l);

}

}

}

}

}

printf("the number of solutions : %d",c);//number of solutions

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote