0% found this document useful (0 votes)
21 views7 pages

Lab 10

Uploaded by

manas.sep20
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views7 pages

Lab 10

Uploaded by

manas.sep20
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

Task 1:

Code:
#include<iostream>

const int M = 100;

void sort(float number[M],int x);

using namespace std;

int main()

int n, i, j;

float value[M];

cout << "Enter the number of values to sort: ";

cin >> n;

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

cout << "Enter the value of "<<i+1<< ": ";

cin >> value[i];

sort(value, n);

cout << "Values in ascending order: ";

for (int k = 0; k < n; k++)

cout <<endl<< value[k];

void sort(float number[M],int x)

int i, j;
float temp=0;

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

for (j = i + 1; j < x; j++)

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

temp = number[i];

number[i] = number[j];

number[j] = temp;

Output:

Task 2:
Code:
#include<iostream>

const int M = 100;

void transpose(float matrix[M][M],float result[M][M], int r,int c);

using namespace std;


int main()

int i, j,rA,cA;

float matrixA[M][M],resultA[M][M];

cout << "Enter the number of rows: ";

cin >> rA;

cout << "Enter the number of columns: ";

cin >> cA;

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

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

cout << "Enter the value of " << i + 1 << ","<<j+1<<": ";

cin >> matrixA[i][j];

cout << "Matrix A: ";

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

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

cout<< matrixA[i][j];

cout << endl;

transpose( matrixA, resultA,rA, cA);

cout << "Transpose matirx: ";


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

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

cout << resultA[i][j];

cout << endl;

void transpose(float matrix[M][M], float result[M][M], int r, int c)

int i, j;

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

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

result[i][j] = matrix[j][i];

Output:
Task 3:
Code:
#include<iostream>

#include<cmath>

const int M = 100;

float average(float marks[M], int x);

float variance(float marks[M], int x);

using namespace std;

int main()

int i, j, n;

float marks[M];

cout << "Enter the number of students: ";

cin >> n;

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

cout << "Enter the marks of " << i + 1 << ": ";
cin >> marks[i];

cout << "Average is : "<<average(marks,n)<<endl;

cout << "Variance is : " << variance(marks, n) << endl;

float average(float marks[M], int x)

int i, j;

float ave,sum=0.0;

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

sum=sum+marks[i];

return ave = sum / x;

float variance(float marks[M], int x)

int i,j;

float ver= 0.0,ave=0;

ave=average(marks, x);

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


{

ver=ver+(pow((marks[i] - ave), 2));

return ver/x;

Output:

You might also like