#include<stdio.h>
#include<conio.h>
#include<math.h>
float triangular(float a,float b,float R)
{
if(a>b)
return (0.0);
else
return(a+(b-a)*R);
}
float exponential(float mean,float R)
{
if(R>1)
return (0.0);
else
return (-1/mean*logl(1-R));
}
float weibull(float alpha,float beta,float R)
{
if(R>1)
return (0.0);
else
return (alpha*(pow(logl(1/(1-R)),1/beta)));
}
void main()
{
float x[10],mean,a,b,r[10];
int i,n,ch;
char c;
clrscr();
printf("How many Random Nos. you want to enter:");
scanf("%d",&n);
while(1)
{
printf("\n\t 1. Exponential \n\t 2. Triangular\n\t 3. Weibull\n\t");
printf("\n\t Enter Your Choice ");
scanf("%d",&ch);
for(i=0;i<n;i++)
r[i]=(float)(rand()%1000)/1000;
switch(ch)
{
case 1: printf("\n\t Enter value mean:");
scanf("%f",&mean);
printf("\n\t r[i] \t x[i]");
for(i=0;i<n;i++)
{
x[i]=exponential(mean,r[i]);
printf("\n\t %.4f \t %.4f", r[i],x[i]);
}
break;
case 2: printf("\n\t Enter the value of a & b:");
scanf("%f%f",&a,&b);
printf("\n\t r[i] \t x[i]");
for(i=0;i<n;i++)
{
x[i]=triangular(a,b,r[i]);
printf("\n\t %.4f \t %.4f", r[i],x[i]);
}
break;
case 3: printf("\n\t Enter value of alpha & beta:");
scanf("%f%f",&a,&b);
printf("\n\t r[i] \t x[i]");
for(i=0;i<n;i++)
{
x[i]=weibull(a,b,r[i]);
printf("\n\t %.4f \t %.4f", r[i],x[i]);
}
break;
default:
printf("Invalid Choice.");
exit(0);
}
}
getch();
}
Comments