Maths File PDF

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 19

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
PRACTICAL FILE

GOVT.COLLEGE.DAULATPUR.CHOWK,UNA.HIMACHAL PRADESH

NAME:.…………………………………………………………CLASS:……………………………………………………

SEMESTER:……………………………………............. ROLL NO:……………………………………………....

SUBMITTED TO:VISHAL SIR SUBMITTED BY:……………………………………………

TEACHER’S SIGNATURE:…………………………………………………………….

You might also like