#include<stdio.h>
#include<conio.h>
#include<dos.h>
#include<graphics.h>
#include<stdlib.h>
float f[20],F[20];
int f1[20],F1[20];
int a,b,i,j,k;
int gm=EGAHI,gd=EGA,errorcode;
float temp[5],mean,var,a1,b1;
char str[20],str1[20];
void display(char str[],float t[],int f1[],int ch)
{ int i,j,k;
float temp[20];
char str1[20];
outtextxy(0,0,str);
for(i=0;i<=12;i++)
{ line(40*i,10,40*(i+1),10);
line(40*i,50,40*(i+1),50);
line(40*i,10,40*i,50);
}
line(40*i,10,40*i,50);
line(0,30,40*13,30);
line(38,10,38,50);
outtextxy(5,20,"x");
if(ch==0)
outtextxy(5,40,"f(x)");
else
outtextxy(5,40,"F(x)");
for(i=1,j=1;i<=12;i++,j++)
{ temp[j]=t[j];
sprintf(str,"%2d",j);
sprintf(str1,"%.2f",temp[j]);
outtextxy(40*i+5,20,str);
outtextxy(40*i+5,40,str1);
delay(150);
}
for(i=0,j=0;i<225;i++,j+=2)
{ putpixel(100,getmaxy()-50-i,getmaxcolor());
putpixel(100+j,getmaxy()-50,getmaxcolor());
putpixel(100+j+1,getmaxy()-50,getmaxcolor());
delay(10);
}
for(i=0;i<10;i++)
{ putpixel(550-i,getmaxy()-50-i,getmaxcolor());
putpixel(550-i,getmaxy()-50+i,getmaxcolor());
putpixel(100-i,getmaxy()-275+i,getmaxcolor());
putpixel(100+i,getmaxy()-275+i,getmaxcolor());
delay(25);
}
settextstyle(0,VERT_DIR,1);
if(ch==0)
outtextxy(50,150,"f(x)->");
else
outtextxy(50,150,"F(x)->");
settextstyle(0,HORIZ_DIR,1);
outtextxy(300,325,"x->");
for(i=0,j=0;i<12;i++,j++)
{ if(j<=10)
{ sprintf(str,"%4.2f",(float)j/10);
putpixel(99,getmaxy()-50-j*20,getmaxcolor());
putpixel(98,getmaxy()-50-j*20,getmaxcolor());
outtextxy(60,getmaxy()-50-j*20,str);
}
line(100+(i*30),getmaxy()-50-f1[i]*2,100+(i+1)*30,getmaxy()-50-f1[i+1]*2);
sprintf(str,"%2d",i);
putpixel(100+(i*30),getmaxy()-49,getmaxcolor());
putpixel(100+(i*30),getmaxy()-48,getmaxcolor());
outtextxy(90+(i*30),getmaxy()-40,str);
delay(150);
}
putpixel(100+(i*30),getmaxy()-49,getmaxcolor());
putpixel(100+(i*30),getmaxy()-48,getmaxcolor());
outtextxy(90+(i*30),getmaxy()-40,"12");
getch();
cleardevice();
}
void main()
{ clrscr();
printf("\nEnter value of intervals.\na:");
scanf("%d",&a);
printf("b:");
scanf("%d",&b);
mean=(float)(a+b)/2;
var=(float)(b-a)*(b-a)/2;
a1=mean;b1=var;
printf("\nMean = %.2f",mean);
printf("\nVariance = %.2f",var);
getch();
for(i=0,j=100;i<=12;i++)
{ if(i>=a && i<=b)
f[i]=(float)1/(b-a);
else
f[i]=0;
f1[i]=f[i]*j;
}
for(i=0,j=100;i<=12;i++)
{ if(i<a)
F[i]=0;
else
{ if(i>=a && i<=b)
F[i]=(float)(i-a)/(b-a);
else
F[i]=1;
}
F1[i]=F[i]*j;
}
clrscr();
initgraph(&gd,&gm,"c:\\tc\\bgi");
errorcode=graphresult();
sprintf(str,"The Probability density function is as follows:");
display(str,f,f1,0);
sprintf(str,"The Cummulative density function is as follows:");
display(str,F,F1,1);
closegraph();
}
#include<conio.h>
#include<dos.h>
#include<graphics.h>
#include<stdlib.h>
float f[20],F[20];
int f1[20],F1[20];
int a,b,i,j,k;
int gm=EGAHI,gd=EGA,errorcode;
float temp[5],mean,var,a1,b1;
char str[20],str1[20];
void display(char str[],float t[],int f1[],int ch)
{ int i,j,k;
float temp[20];
char str1[20];
outtextxy(0,0,str);
for(i=0;i<=12;i++)
{ line(40*i,10,40*(i+1),10);
line(40*i,50,40*(i+1),50);
line(40*i,10,40*i,50);
}
line(40*i,10,40*i,50);
line(0,30,40*13,30);
line(38,10,38,50);
outtextxy(5,20,"x");
if(ch==0)
outtextxy(5,40,"f(x)");
else
outtextxy(5,40,"F(x)");
for(i=1,j=1;i<=12;i++,j++)
{ temp[j]=t[j];
sprintf(str,"%2d",j);
sprintf(str1,"%.2f",temp[j]);
outtextxy(40*i+5,20,str);
outtextxy(40*i+5,40,str1);
delay(150);
}
for(i=0,j=0;i<225;i++,j+=2)
{ putpixel(100,getmaxy()-50-i,getmaxcolor());
putpixel(100+j,getmaxy()-50,getmaxcolor());
putpixel(100+j+1,getmaxy()-50,getmaxcolor());
delay(10);
}
for(i=0;i<10;i++)
{ putpixel(550-i,getmaxy()-50-i,getmaxcolor());
putpixel(550-i,getmaxy()-50+i,getmaxcolor());
putpixel(100-i,getmaxy()-275+i,getmaxcolor());
putpixel(100+i,getmaxy()-275+i,getmaxcolor());
delay(25);
}
settextstyle(0,VERT_DIR,1);
if(ch==0)
outtextxy(50,150,"f(x)->");
else
outtextxy(50,150,"F(x)->");
settextstyle(0,HORIZ_DIR,1);
outtextxy(300,325,"x->");
for(i=0,j=0;i<12;i++,j++)
{ if(j<=10)
{ sprintf(str,"%4.2f",(float)j/10);
putpixel(99,getmaxy()-50-j*20,getmaxcolor());
putpixel(98,getmaxy()-50-j*20,getmaxcolor());
outtextxy(60,getmaxy()-50-j*20,str);
}
line(100+(i*30),getmaxy()-50-f1[i]*2,100+(i+1)*30,getmaxy()-50-f1[i+1]*2);
sprintf(str,"%2d",i);
putpixel(100+(i*30),getmaxy()-49,getmaxcolor());
putpixel(100+(i*30),getmaxy()-48,getmaxcolor());
outtextxy(90+(i*30),getmaxy()-40,str);
delay(150);
}
putpixel(100+(i*30),getmaxy()-49,getmaxcolor());
putpixel(100+(i*30),getmaxy()-48,getmaxcolor());
outtextxy(90+(i*30),getmaxy()-40,"12");
getch();
cleardevice();
}
void main()
{ clrscr();
printf("\nEnter value of intervals.\na:");
scanf("%d",&a);
printf("b:");
scanf("%d",&b);
mean=(float)(a+b)/2;
var=(float)(b-a)*(b-a)/2;
a1=mean;b1=var;
printf("\nMean = %.2f",mean);
printf("\nVariance = %.2f",var);
getch();
for(i=0,j=100;i<=12;i++)
{ if(i>=a && i<=b)
f[i]=(float)1/(b-a);
else
f[i]=0;
f1[i]=f[i]*j;
}
for(i=0,j=100;i<=12;i++)
{ if(i<a)
F[i]=0;
else
{ if(i>=a && i<=b)
F[i]=(float)(i-a)/(b-a);
else
F[i]=1;
}
F1[i]=F[i]*j;
}
clrscr();
initgraph(&gd,&gm,"c:\\tc\\bgi");
errorcode=graphresult();
sprintf(str,"The Probability density function is as follows:");
display(str,f,f1,0);
sprintf(str,"The Cummulative density function is as follows:");
display(str,F,F1,1);
closegraph();
}
No comments:
Post a Comment