forked from angminsheng/Hacktoberfest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
no. of integral sol.c
43 lines (40 loc) · 1.13 KB
/
no. of integral sol.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include <stdio.h>
int main()
{
int i,testcs;
int eqn[100],num[100];
printf("Enter the test-cases you want: ");
scanf("%d",&testcs);
for(i=0;i<testcs;i++)
{
printf("For Equation %d, Enter no.of variables: ",i+1);
scanf("%d",&eqn[i]);
printf("Enter number for which solutions are required: ");
scanf("%d",&num[i]);
}
int j,fac1[100],fac2[100],fac3[100],ans[100];
for(i=0;i<testcs;i++)
{
fac1[i]=1;
fac2[i]=1;
fac3[i]=1;
for(j=1;j<=(num[i] - 1);j++)
fac1[i] = fac1[i] * j;
for(j=1;j<=(eqn[i] - 1);j++)
fac2[i] = fac2[i] * j;
for(j=1;j<=(num[i] - eqn[i]);j++)
fac3[i] = fac3[i] * j;
printf("\n No. of integral solutions of equation ");
for(j=0;j<eqn[i];j++)
{
if(j == (eqn[i]-1))
printf("%c = ",(j+97));
else
printf("%c + ",(j+97));
}
printf("%d are ",num[i]);
ans[i] = fac1[i] / (fac2[i] * fac3[i]);
printf("%d\n",ans[i]);
}
return 0;
}