Note.....

Dear readers I Have collected these Programs from various sources of internet...I don't know what the header file is Please mail me if any error found hi2rashid@yahoo.co.in

Sponsored....

Tuesday, April 13, 2010

Program for (probability 1)

//Program for (probability 1)

#include
#include
#include
float nCr(int n,int r);
float fact(int n) ;
void main()
{
textcolor(YELLOW);
clrscr();
int r,b,w,t,r1,b1,w1,t1;float prob,p1,p2,p3,sam_s;
cout<<"enter the number of red balls : ";
cin>>r;
cout<<"enter the number of blue balls : ";
cin>>b;
cout<<"enter the number of white balls : ";
cin>>w;
t=r+b+w;
cout<<"enter the number of red ball drawn : ";
cin>>r1;
cout<<"enter the number of blue ball drawn : ";
cin>>b1;
cout<<"enter the number of white ball drawn : ";
cin>>w1;
t1=r1+b1+w1;
sam_s=nCr(t,t1);
p1=nCr(r,r1);p2=nCr(b,b1);p3=nCr(w,w1);
prob=(p1*p2*p3)/sam_s;
cout<<"\nthe probability of drawing "<<<" red "<<<" blue "<<<"
white balls is : "<
delay(100);
textcolor(RED);
cout<<"\n\n\a";
cprintf("PROGRAM DESIGNED BY:PRASHANT KUMAR SINGH");
cout<<"\n\n";
cprintf("BRANCH : ECE / 3rd semester / roll 194/06 ");

getch();
}

float fact(int n)
{float fn=1;
if(n==0)
return(1);
else
{
for(int i=1;i<=n;i++)
fn*=i;
return(fn);
}
}

float nCr(int n,int r)
{
float C=fact(n)/(fact(r)*fact(n-r));
return(C);
}

output:

enter the number of red balls : 3
enter the number of blue balls : 7
enter the number of white balls : 6
enter the number of red ball drawn : 0
enter the number of blue ball drawn : 1
enter the number of white ball drawn : 1

the probability of drawing 0 red 1 blue 1 white balls is : 0.35

No comments:

Post a Comment