Favorite Dice
Link to the question : FAVDICE
HINT :
Read some articels on : Expected value. Understand it properly and then implement the formula.
SOURCE CODE :
#include<stdio.h>
int main()
{
int t,n,i;
float s;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
s=0;
for(i=1;i<=n;i++)
s= s+ (float)1/(i);
s=(float)(s*n);
printf("%.2f\n",s);
}
return 0;
}
RECOMMENDED QUESTION :
I would like my reader to solve this question after this one.
No comments:
Post a Comment