0% found this document useful (0 votes)
28 views21 pages

Cosm PF

The document contains 9 questions and answers related to calculating statistical measures like mean, mode, median, variance, standard deviation and quartiles from data. It includes programs to find these measures from both given data sets and data entered by the user.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views21 pages

Cosm PF

The document contains 9 questions and answers related to calculating statistical measures like mean, mode, median, variance, standard deviation and quartiles from data. It includes programs to find these measures from both given data sets and data entered by the user.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 21

PRACTICAL FILE

Govt. College Daulatpur Chowk, Una, Himachal Pradesh

Name: ……………………………………… Class: …………………………………….

Roll No.: …………………………………… Session: ……………………………………

Submitted To: Submitted By:

AP Vishal Kanwar ……………………………………

Teacher’s Signature: ……………………………………


INDEX

Sr. No. Name Of Practical Page No. Remarks


1 Write a program to find the mean of 1
given numbers.
2 Write a program to find the mean of the 2
data entered by the user.
3 Write a program to find the mode of the 3-4
data.
4 Write a program to find the mode of the 5-6
data entered by the user.
5 Write a program to find the median of 7-8
the data.
6 Write a program to find the median of 9-10
the data entered by the user.
7 Write a program to find the variance 11-12
and standard deviation of the user’s
entered data.
8 Write a program to find the median for 13-15
the continuous series.
9 Write a program to calculate the 16-18
quartile of discrete series.
QUESTION 1: FIND THE MEAN OF GIVEN NUMBERS?
ANSWER:
#include<stdio.h>
int main()
{
int num=5,i,sum=0,mean;
int a[]={15,10,25,35,20};
for ( i = 0; i <=num ; i++)
{
sum=sum+a[i];
}
mean=sum/5;
printf("The mean is => %d",mean);
return 0;
}

1
QUESTION: FIND THE MEAN OF THE DATA ENTERED BY THE
USER?
ANSWER:
#include<stdio.h>

int main()

int num=5,i;

float sum=0,mean,a[10];

printf("enter the number you want to find the mean: \n");

scanf("%d",&num);

for ( i = 0; i <=num-1; i++)

printf("Enter the %d number: ",i+1);

scanf("%f",&a[i]);

sum=sum+a[i];

mean=sum/num;

printf("The mean is => %.2f",mean);

return 0;

2
QUESTION: WRITE A PROGRAM TO FIND THE MODE OF THE DATA?

ANSWER:

#include<stdio.h>

int mode(int a[],int n)

int maxValue=0,maxCount=0,i,j;

for ( i = 0; i <n; i++)

int count=0;

for ( j = 0; j < n; j++)

if (a[j]==a[i])

++count;

if (count> maxCount)

maxCount=count;

maxValue=a[i];

return maxValue;

int main()

int n=5;

int a[]={0,6,7,2,7};

printf(" the Mode is = %d",mode(a,n));

return 0;

} 3
4
QUESTION:FIND THE MODE OF THE DATA ENTERED BY THE USER?

ANSWER:

#include<stdio.h>

int mode(int a[],int n)

int maxValue=0,maxCount=0,i,j;

for ( i = 0; i <n; i++)

int count=0;

for ( j = 0; j < n; j++)

if (a[j]==a[i])

++count;

if (count> maxCount)

maxCount=count;

maxValue=a[i];

return maxValue;

int main()

int n,i,a[50];

printf("Enter how many numbers you want to add: ");

scanf("%d",&n);

for(i=0;i<n;i++)

printf("Enter the %d numbers : ",i+1); 5


scanf("%d",&a[i]);

printf(" the Mode is = %d",mode(a,n));

return 0;

6
QUESTION:FIND MEDIAN OF THE ENTERED DATA?

ANSWER:
#include <stdio.h>

void swap(int *p, int *q)

int t;

t = *p;

*p = *q;

*q = t;

void sort(int a[], int n)

int i, j, temp;

for (i = 0; i < n - 1; i++)

for (j = 0; j < n - i - 1; j++)

if (a[j] > a[j + 1])

swap(&a[j], &a[j + 1]);

int main()

int a[]={6,3,8,5,1};

int n=5;

int sum,i;

sort(a,n);

n=(n+1)/2-1; 7
printf("Median is = %d",a[n]);

return 0;

8
QUESTION:FIND THE MEDIAN OF THE DATA ENTERED BY THE USER?

ANSWER:
#include <stdio.h>

void swap(int *p, int *q)

int t;

t = *p;

*p = *q;

*q = t;

void sort(int a[], int n)

int i, j, temp;

for (i = 0; i < n - 1; i++)

for (j = 0; j < n - i - 1; j++)

if (a[j] > a[j + 1])

swap(&a[j], &a[j + 1]);

int main()

int a[50];

int n;

int sum, i;

printf("enter how many numbers you want to find median: ");

scanf("%d", &n); 9
for (i = 0; i < n; i++)

printf("enter the %d number: ",i + 1);

scanf("%d", &a[i]);

sort(a, n);

n = (n + 1) / 2 - 1;

printf(" THE MEDIAN IS = %d", a[n]);

return 0;

10
QUESTION:FIND THE VARIANCE AND STANDARD DEVIATION OF THE USER’S ENTERED DATA?

ANSWER:

#include<stdio.h>

#include<math.h>

float Standard_Deviation(float price[],int number)

float mean,variance,sd,sum=0,varsum=0;

int i;

for ( i = 0; i < number; i++)

sum=sum+price[i];

mean=sum/(float)number;

for ( i = 0; i <number; i++)

varsum=varsum+pow((price[i]-mean),2);

variance=varsum/(float)number;

sd=sqrt(variance);

printf("The mean is = %.2f\n",mean);

printf("The variance is = %.2f\n",variance);

return sd;

int main()

float price[]={5,15,25,35,45,55};

float SD;

int i,Number=6;

//calling the function

SD=Standard_Deviation(price,Number);

printf("Standard Deviation is = %.2f\n",SD);

return 0; 11
}

12
QUESTION: WRITE A PROGRAM TO FIND THE MEDIAN FOR CONTINUOUS
SERIES?

ANSWER:

#include<stdio.h>

int i,j,ll,up,cl,nc,l[100],u[100],f[100],sf,am,cf[100],temp,x[100];

void continuous()

printf("Enter the lower limit: \n");

scanf("%d",&ll);

printf("Enter the class length: \n");

scanf("%d",&cl);

printf("Enter the total number of classes: \n");

scanf("%d",&nc);

for ( i = 0; i < nc; i++)

up=ll+cl;

l[i]=ll;

u[i]=up;

ll=up;

x[i]=((float)l[i]+(float)u[i]/2);

printf("\n");

for ( i = 0; i < nc; i++)

printf("Enter the frequency for class %d-%d:",l[i],u[i]);

scanf("%d",&f[i]);

cf[0]=f[0]; 13
for ( i = 0; i < nc; i++)

cf[i+1]=cf[i]+f[i+1];

for ( i = 0; i < nc; i++)

sf+=f[i];

for ( i = 0; i < nc; i++)

if (sf/2>=cf[i])

temp=i+1;

printf("class \t freq\tC.f. :");

for ( i = 0; i < nc; i++)

printf("\n%d-%d\t%d\t%d",l[i],u[i],f[i],cf[i]);

printf("\nTotal :\t%d",sf);

printf("\n\nXI:%d n/2:%.2f F<%d f:%d


C:%d",l[temp],(float)sf/(float)2,cf[temp-1],cl);

printf("\nThe median is: %.4f",l[temp]+(((((float)sf/(float)2)-cf[temp-


1])/f[temp])*cl));

int main()

{ 14
continuous();

return 0;

15
QUESTION:WRITE A PROGRAM TO CALCULATE THE QUARTILE OF DISCRETE
SERIES?

ANSWER:

#include <stdio.h>

#define SIZE 100

int i, n, j, x[SIZE], median, temp, temp1, f[SIZE], cf[SIZE], INDEX[SIZE],


sort[SIZE];

int main()

printf("Enter the number of items: ");

scanf("%d", &n);

for (i = 0; i < n; i++)

printf("Enter the observation %d :", i + 1);

scanf("%d", &x[i]);

printf("Enter the frequency: ");

scanf("%d", &f[i]);

sort[i] = f[i];

cf[0] = f[0];

for (i = 0; i < n; i++)

cf[i + 1] = cf[i] + f[i + 1];

printf("\nxi \tfi \tci\n");

for (i = 0; i < n; i++)

printf("\n%d \t%d \t%d\n ", x[i], f[i], cf[i]); 16


}

for (i = 0; i < n - 1; i++)

for (j = 0; j < n; j++)

if (sort[i] > sort[j])

// exchange them

temp = sort[i];

sort[i] = sort[j];

sort[j] = temp;

for (i = 0; i < n; i++)

printf("%d", sort[i]);

for (i = 0; i <= 3; i++)

printf("\nQUARTILE %d ==>", i);

printf("\nQ%d is %d", i, sort[(i * (n + 1)) / 4 - 1]);

return 0;

17
18

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy