Skip to main content

Posts

Showing posts from October 25, 2011

Coding for distributions (geometric/weibull)

#include #include #include long fact(int n) { if(n 0) return pow(q,x-1)*p; else return 0; } double weibpdf(int x, double v, double a, double b) { if(x =0) return fact(n)/(fact(x)*fact(n-x))*pow(p,x)*pow(q,n-x); else return 0; } int main() { int ch; double p,q,v,a,b; int x,n; clrscr(); do { printf("\nExit."); printf("\nGeometric Mean."); printf("\nWeibull Distribution."); printf("\nPoisson Distribution."); printf("\nBinomial Distribution."); printf("\nEnter your choice => "); scanf("%d",&ch); if(ch==1) { printf("\n\tEnter the value of x,p,q => "); scanf("%d%lf%lf",&x,&p,&q); printf("\n\tGeometric Mean = %lf",geomean(x,p,q)); } else if(ch==2) { printf("\n\tEnter the value...

Coding for M/M/1 server

#include #include void main() { int i,a,d,arrival[11],clock=0,inter[]={2,3,1,4,1,6,1,1,5,2,1},service[]= {2,5,4,3,3,5,6,6,6,3,2}; int wait[11],q=0,sum=0,avg,server; arrival[0]=clock+inter[0]; d=clock+service[0]; server=1; a=arrival[0]; wait[0]=0; for(i=0;i d) {wait[i]=0; printf("clock=%d (A=%d)(D=%d)(W=%d)",clock,a,d,wait[1]) ; i++; } else if(d a) { wait[i]=d-a; } printf("\nclock = %d (A,%d) (D,%d) (w,%d)",clock,a,d,wait[i]); } else { wait[i]=0; printf("clock=%d (A=%d)(D=%d)(W=%d)",clock,a,d,wait[i]) ; server=0; } } else { clock=0; a=arrival[i]; d=clock+service[i-q]; if(a { wait[i]=d-a; } else { wait[i]=0; i++; printf("clock=%d (A=%d)(D=%d)(W=%d)",clock,a,d,wait[i]) ; } } else { clock=0; a=arrival[i]; d=clock+service[i]; wait[i]=d-a; i++; printf("clock=%d (A=%d)(D=%d)(W=%d)",clock,a,d,wait[i]) ; for(i=0;i { sum+=wait[i]; } avg=sum/11; if (avg printf("efficient system...