How to Write a c program to generate P-Chart in statistics for the control limit. wap to computing the control limits of P-chart.
C program to generate P-chart in statistics
#include<conio.h>
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
void direct();
void indirect();
long int I_num, S_num, num, i, D_num;
long int dfct=0, d[50];
float cl, ucl, lcl, z ;
void main()
{
int ch;
clrscr();
while(ch!=5)
{
printf("\nenter your choice ");
printf("\npress 1 for direct central line is given ");
printf("\npress 2 for finding central line ");
printf("\npress 3 for exit ");
printf("\n");
scanf("%d",&ch);
switch(ch)
{
case 1 :
direct();
break;
case 2 :
indirect();
break;
case 3 :
exit(0);
break;
default :
printf("\nu enter wrong choice \n");
break;
}
}
getch();
}
void direct()
{
printf("\n enter the value of central line = ");
scanf("%f",&cl);
printf("\n enter the total no of items in each sample inspected = ");
scanf("%ld",&I_num);
z=(cl*(1-cl))/I_num;
z=sqrt(z);
ucl=cl+3*z;
lcl=cl-3*z;
if(lcl<0)
lcl=0;
printf("\nthe value of central line cl = %.3f",cl);
printf("\nthe value of upper control limit ucl = %.3f",ucl);
printf("\nthe value of lower control limit lcl = %.3f\n",lcl);
}
void indirect()
{
printf("\n enter the total no of samples inspected = ");
scanf("%ld",&S_num);
printf("\n enter the total no of items in each sample inspected = ");
scanf("%ld",&I_num);
printf("\n enter the total no of defective items in samples inspected = ");
scanf("%ld",&D_num);
printf("\n enter the no of defective items in samples one by one \n");
for(i=0;i<D_num;i++)
{
scanf("%ld",&d[i]);
}
for(i=0;i<D_num;i++)
{
dfct=dfct+d[i];
}
cl=(float)dfct/(S_num*I_num);
z=(cl*(1-cl))/I_num;
z=sqrt(z);
ucl=cl+3*z;
lcl=cl-3*z;
if(lcl<0)
lcl=0;
printf("\nthe value of central line cl = %.3f",cl);
printf("\nthe value of upper control limit ucl = %.3f",ucl);
printf("\nthe value of lower control limit lcl = %.3f\n",lcl);
}