How to Write a C program to generate R-Chart in statistics.
C program to generate R-Chart in statistics
#include<conio.h>
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#define D3 0
#define D4 2.115
void direct();
void indirect();
int num, r[50], i;
float 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 range is given ");
printf("\npress 2 for finding mean of sampling 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 ranges i.e. R bar = ");
scanf("%f",&R_m);
ucl=D4*R_m;
lcl=D3*R_m;
printf("\nthe value of central line R_m = %.3f",R_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 ranges \n");
for(i=0;i<num;i++)
{
scanf("%d",&r[i]);
}
for(i=0;i<num;i++)
{
r_m=r_m+r[i];
}
R_m=(float)r_m/num;
ucl=D4*R_m;
lcl=D3*R_m;
printf("\nthe value of central line R_m = %.3f",R_m);
printf("\nthe value of upper control limit ucl = %.3f",ucl);
printf("\nthe value of lower control limit lcl = %.3f\n",lcl);
}