How to write C program to generate X-Chart in statistic.
C Program to generate X-Cahrt in Statistic
#include<conio.h> #include<stdio.h> #include<math.h> #include<stdlib.h> #define A2 .577 void direct(); void indirect(); int num, x[50], r[50], i; float x_m=0.0, X_m, r_m=0.0, R_m, ucl, lcl; void main() { int ch; clrscr(); while(ch!=5) { printf("\nenter your choice "); printf("\npress 1 for direct mean of sampling and range are given "); printf("\npress 2 for finding mean of sampling and range "); 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 mean of all given mean i.e. X bar ka bar = "); scanf("%f",&X_m); printf("\n enter the value of mean of all given ranges i.e. R bar = "); scanf("%f",&R_m); ucl=X_m+(A2*R_m); lcl=X_m-(A2*R_m); printf("\nthe value of central line X_m = %.3f",X_m); 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 no of samples = "); scanf("%d",&num); printf("\n enter the values of mean \n"); for(i=0;i<num;i++) { scanf("%d",&x[i]); } printf("\n enter the values of ranges \n"); for(i=0;i<num;i++) { scanf("%d",&r[i]); } for(i=0;i<num;i++) { x_m=x_m+x[i]; } for(i=0;i<num;i++) { r_m=r_m+r[i]; } X_m=(float)x_m/num; R_m=(float)r_m/num; ucl=X_m+(A2*R_m); lcl=X_m-(A2*R_m); printf("\nthe value of central line X_m = %.3f",X_m); printf("\nthe value of upper control limit ucl = %.3f",ucl); printf("\nthe value of lower control limit lcl = %.3f\n",lcl); }