/*acception rejection using poisson*/
#include<stdio.h>
#include<conio.h>
#include<math.h>
#include<stdlib.h>
main()
{
float p[30],r[30],random[30],a;
int i,j,k,n;
int count =0;
int flag=0;
printf("Enter the number of random numbers \t e.g 5\n");
scanf("%d",&n);
printf("enter the value of alpha \t e.g 0.2 \n");
scanf("%f",&a);
random[0]=0.4357;
random[1]=0.4146;
random[2]=0.8353;
random[3]=0.9952;
random[4]=0.8004;
printf("\n");
p[0]=1;
system("cls");
printf("n\t\tR(n+i)\t\tP\t\tAcc/Rej\n");
i=0;
p[i+1]= p[0] * random[i];
while(i<n)
{
if(p[i+1] < exp(-a))
{
printf("\n%d\t%f\t%f\t%s",count,random[i],p[i+1],"accept");
i++;
p[i+1]= p[0] * random[i];
}
else if(p[i+1] >= exp(-a))
{
printf("\n%d\t%f\t%f\t%s",count,random[i],p[i+1],"reject");
i++;
count++;
p[i+1]= p[i]*random[i];
}
}
getch();
}
Comments