This Question has been **Answered**

0

honestly i was new to C and i just need a codes for finding the mean for grouped data. i hope this site can least help me. you have my thanks.

Nobody's gonna provide you a full working code for you, you should write it yourself.This site does help those who "help themselves".

What do you "mean" by "grouped data"?

Have you started yet or you're hoping that someone here will give you the code(not even knowing what you actually want),if the case is latter you're gonna be very disappointed.

In the former case, you might post next time with the exact questions(of where you're stuck in your program and with what exactly you need help with).

0

sample mean; grouped data is arranged and more likely to be tabular. actually i have started but i'm stuck with frequency distribution and i barely can't find it so i ask assistance for anyone here. so you may want to see my codes? after all thank you sir for your comment.

*Edited
by reojavier*: redundant word

0

```
#include<stdio.h>
#include<conio.h>
int intpart(float x)
{
return x;
}
float decpart(float x)
{
return x - intpart(x);
}
int roundoff(float x)
{
if(decpart(x) >= 0.5)
{
return int part(x) + 1;
}
else
{
return intpart(x);
}
}
int main()
{
int arx[100],n,a,b,hs,ls,range,cs;
int arlow[11], arhigh[11];
float arcm;
clrscr():
printf("Enter number of scores: "); scanf("%i", &n);
if(n<1 || n > 100)
{
printf("Invalid no. of scores");
getch();
return 1;
}
for(a=0; a<n; a++)
{
printf("%i", a+1);
scanf("%i", &arx[a]);
}
hs = arx[0];
for(a=1; a<n; a++)
{
if(arx[a] > hs)
{
hs = arx[a];
}
}
ls = arx[0];
for(a=1; a<n; a++)
{
if(arx[a] < ls)
{
ls = arx[a];
}
}
range = hs - ls;
cs = roundoff(range / 10.0)
a=0;
x=ls;
while(x<=hs)
{
arlow[a] = x;
arhigh[a] = x + cs - 1;
arcm[a] = (arlow[a] + arhigh[a])/2.0;
x = x + cs;
a++;
}
a--;
for(b=a; b>=0; b--)
{
prinf("\n%i\t%i\t%.2f", arlow[b], arhigh[b], arcm[b]);
}
printf("\nhighest score: %i", hs);
printf("\nlowest score: %i", ls);
printf("\nrange: %i", range);
printf("\nclass size: %i", cs);
//some codes missing
getch():
return 0;
}
```

arx is array

n is number of scores

ls is lowest score

hs is highest score

cs is class size

arhigh is upper limit

arlow is lower limit

arcm is class mark

0

It's a good thing that you posted your code, but you should compile it first to see if there are any typing errors or syntax mistakes.Here I have posted your code with some corrections.There are comments in each corrected line so you can easily match it with your original code to see where the mistakes were.

You'd better not use the non standard header "conio.h",since it is not portable.getchar() will do same thing as getch(),except you may have to press an extra <enter> key to get the job done.

```
#include<stdio.h>
#include<conio.h>//don't use this header
int intpart(float x)
{
return x;
}
float decpart(float x)
{
return x - intpart(x);
}
int roundoff(float x)
{
if(decpart(x) >= 0.5)
{
return intpart(x) + 1;/*no space between int and part*/
}
else
{
return intpart(x);
}
}
int main()
{
int arx[100],n,a,b,hs,ls,range,cs;
int arlow[11], arhigh[11];
float arcm[11]; //may be you should declare arcm as an array of 11 floats
clrscr(); /*had used colon instead of semicolon, why do you need to clear the console anyway*/
printf("Enter number of scores: "); scanf("%i", &n);
if(n<1 || n > 100)
{
printf("Invalid no. of scores");
getch();//use getchar() instead
return 1;
}
for(a=0; a<n; a++)
{
printf("%i", a+1);
scanf("%i", &arx[a]);
}
hs = arx[0];
for(a=1; a<n; a++)
{
if(arx[a] > hs)
{
hs = arx[a];
}
}
ls = arx[0];
for(a=1; a<n; a++)
{
if(arx[a] < ls)
{
ls = arx[a];
}
}
range = hs - ls;
cs = roundoff(range / 10.0);//missed semicolon
a=0;
int x=ls;//x was used before its declaration
while(x<=hs)
{
arlow[a] = x;
arhigh[a] = x + cs - 1;
arcm[a] = (arlow[a] + arhigh[a])/2.0;//here arcm is not an array*
x = x + cs;
a++;
}
a--;
for(b=a; b>=0; b--)
{
printf("\n%i\t%i\t%.2f", arlow[b], arhigh[b], arcm[b]);//typed prinf instead printf,arcm is not an array*
}
printf("\nhighest score: %i", hs);
printf("\nlowest score: %i", ls);
printf("\nrange: %i", range);
printf("\nclass size: %i", cs);
//some codes missing
getch();//used colon instead of semicolon
return 0;
}
```

*Edited
by D33wakar*: n/a

0

Forgive me if I'm confused, but from the look of your code, you should be well aware of how to calculate the mean from an array (I assume you're talking about the arithmetic mean):

```
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define N 50
double mean(int a[], int n)
{
int sum = 0;
for (int i = 0; i < n; i++)
sum += a[i];
return (double)sum / n;
}
double standard_deviation(int a[], int n, double mean)
{
double variance = 0;
for (int i = 0; i < n; i++) {
int diff = a[i] - mean;
variance += (diff * diff);
}
variance /= n;
return sqrt(variance);
}
int main(void)
{
int a[N];
srand((unsigned)time(NULL));
for (int i = 0; i < N; i++)
a[i] = rand() % N;
double avg = mean(a, N);
printf("Mean: %f\n", avg);
printf("Standard Deviation: %f\n", standard_deviation(a, N, avg));
}
```

I also threw in the standard deviation, because that tends to go hand in hand with the mean.

0

it is okay. yes it is the arithmetic mean i was pointing out. thank you for your effort, it is really a big help. i'll now analyze your codes. :)

This question has already been answered. Start a new discussion instead.

Recommended Topics

i've got code like this

```
naglibog.CommandText = "UPDATE ptransaction " & _
" SET Quantityt = " & mm & _
", Partial_totalt='" & jj & "'" & _
" ...
```

I have completed vb.net program (a school timetabling program) and I am in the process to create a website. At the moment word -press on wamp server ...

(1) whenever log file (system.log) size >30859 or file ...