//PROGRAM OF DICES
/*MADE BY KRISHNA AGARWAL*/
#include<iostream.h>
#include<conio.h>
int main()
{
int i,dices,j,k,n,s,counter=0,b=0,c,count=0;
float p,z;
char ch;
do
{
cout<<"\nenter the number of dice u want to throw i.e 1,2 or 3 ?\n";
cin>>dices;
switch(dices)
{
case 1:
cout<<"\nHere are the outcomes when a single dice is thrown\n";
for(i=1;i<7;i++)
cout<<i<<",";
cout<<"\n\nto find probability of the following occurence:\n";
cout<<"press 1 for even number\n";
cout<<"press 2 for odd number\n";
cout<<"press 3 for prime number\n";
cin>>b;
switch(b)
{
case 1:
cout<<"\npossible outcomes are\n";
for(i=1;i<7;i++)
{
if(i%2==0)
cout<<i<<",";
}
cout<<"\nthe probability is 0.5\n";
break;
case 2:
cout<<"\npossible outcomes are\n";
for(i=1;i<7;i++)
{
if(i%2==1)
cout<<i<<",";
}
cout<<"\nthe probability is 0.5\n";
break;
case 3:
cout<<"\npossible outcomes are\n";
cout<<"\n2,3,5\n";
cout<<"\nthe probability is 0.5\n";
}
break;
case 2:
cout<<"\nhere are the outcomrs when two dices are thrown\n";
for(i=1;i<7;i++)
{
for(j=1;j<7;j++)
cout<<"("<<i<<","<<j<<")"<<"\t";
cout<<"\n\n";
}
cout<<"enter eny number b/w 2 and 12\n";
cin>>c;
for(i=1;i<7;i++)
{
for(j=1;j<7;j++)
{
if(i+j==c)
{
cout<<"("<<i<<","<<j<<")\n";
count++;
}
}
}
cout<<"the total no of possible combinations are\t"<<count;
z=count/36.0;
cout<<"\nhere is the probabilty\t"<<z;
break;
case 3:
cout<<"\n HERE ARE THE OUTCOMES WHEN THREE DICES ARE THROWN\n";
for(i=1;i<7;i++)
{
for(j=1;j<7;j++)
{
for(k=1;k<7;k++)
cout<<"("<<i<<","<<j<<","<<k<<")";
cout<<endl;
}
cout<<endl;
}
cout<<"\n ENTER ANY NUMBER BETWEEN 3 TO 18\n";
cin>>n;
for(i=1;i<7;i++)
{
for(j=1;j<7;j++)
{
for(k=1;k<7;k++)
{
s=i+j+k;
if(s==n)
{
cout<<"("<<i<<","<<j<<","<<k<<")"<<endl;
counter++;
}
}
}
}
cout<<"\nthe total no of possible combinations are\t"<<counter;
p=counter/216.0;
cout<<"\nthe probability is \t"<<p;
break;
}
cout<<"\npress y to continue and x to exit\n";
cin>>ch;
}while(ch=='y');
return 0;
}
/*MADE BY KRISHNA AGARWAL*/
#include<iostream.h>
#include<conio.h>
int main()
{
int i,dices,j,k,n,s,counter=0,b=0,c,count=0;
float p,z;
char ch;
do
{
cout<<"\nenter the number of dice u want to throw i.e 1,2 or 3 ?\n";
cin>>dices;
switch(dices)
{
case 1:
cout<<"\nHere are the outcomes when a single dice is thrown\n";
for(i=1;i<7;i++)
cout<<i<<",";
cout<<"\n\nto find probability of the following occurence:\n";
cout<<"press 1 for even number\n";
cout<<"press 2 for odd number\n";
cout<<"press 3 for prime number\n";
cin>>b;
switch(b)
{
case 1:
cout<<"\npossible outcomes are\n";
for(i=1;i<7;i++)
{
if(i%2==0)
cout<<i<<",";
}
cout<<"\nthe probability is 0.5\n";
break;
case 2:
cout<<"\npossible outcomes are\n";
for(i=1;i<7;i++)
{
if(i%2==1)
cout<<i<<",";
}
cout<<"\nthe probability is 0.5\n";
break;
case 3:
cout<<"\npossible outcomes are\n";
cout<<"\n2,3,5\n";
cout<<"\nthe probability is 0.5\n";
}
break;
case 2:
cout<<"\nhere are the outcomrs when two dices are thrown\n";
for(i=1;i<7;i++)
{
for(j=1;j<7;j++)
cout<<"("<<i<<","<<j<<")"<<"\t";
cout<<"\n\n";
}
cout<<"enter eny number b/w 2 and 12\n";
cin>>c;
for(i=1;i<7;i++)
{
for(j=1;j<7;j++)
{
if(i+j==c)
{
cout<<"("<<i<<","<<j<<")\n";
count++;
}
}
}
cout<<"the total no of possible combinations are\t"<<count;
z=count/36.0;
cout<<"\nhere is the probabilty\t"<<z;
break;
case 3:
cout<<"\n HERE ARE THE OUTCOMES WHEN THREE DICES ARE THROWN\n";
for(i=1;i<7;i++)
{
for(j=1;j<7;j++)
{
for(k=1;k<7;k++)
cout<<"("<<i<<","<<j<<","<<k<<")";
cout<<endl;
}
cout<<endl;
}
cout<<"\n ENTER ANY NUMBER BETWEEN 3 TO 18\n";
cin>>n;
for(i=1;i<7;i++)
{
for(j=1;j<7;j++)
{
for(k=1;k<7;k++)
{
s=i+j+k;
if(s==n)
{
cout<<"("<<i<<","<<j<<","<<k<<")"<<endl;
counter++;
}
}
}
}
cout<<"\nthe total no of possible combinations are\t"<<counter;
p=counter/216.0;
cout<<"\nthe probability is \t"<<p;
break;
}
cout<<"\npress y to continue and x to exit\n";
cin>>ch;
}while(ch=='y');
return 0;
}
No comments:
Post a Comment