How to write a C program for NP – chart of control limit for statistical
/* wap to computing the control limits of NP-chart */
C program to generate NP-chart
#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, p ; void main() { int ch; clrscr(); while(ch!=5) { printf("\nenter your choice "); printf("\npress 1 for direct value of p-bar 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 p-bar = "); scanf("%f",&p); printf("\n enter the total no of items in each sample = "); scanf("%ld",&I_num); cl=p*I_num; z=cl*(1-p); 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 = "); scanf("%ld",&I_num); printf("\n enter the total no of defective of all samples inspected = "); scanf("%ld",&D_num); printf("\n enter the no of defectives 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]; } p=(float)dfct/(S_num*I_num); cl=p*I_num; z=cl*(1-p); 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); }