0% found this document useful (0 votes)
22 views4 pages

OOP Exp1

Uploaded by

rohitkadam25635
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)
22 views4 pages

OOP Exp1

Uploaded by

rohitkadam25635
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/ 4

EXPERIMENT -01

➢ Sorting of an Array:

#CODE
#include<iostream>
using namespace std;

void read(int [], int &);


void display(int [], int);
void swap(int &, int &);
void sort(int [], int &n);

int main()
{
int n,arr[10];
read(arr,n);
display(arr,n);
sort(arr,n);
display(arr,n);
return 0;
}

void read(int a[], int &n)


{
cout<<"Enter number of elements in array:";
cin>>n;
cout<<"Enter data:\n";
for(int i=0;i<n;i++)
cin>>a[i];
}

void display(int a[], int n)


{
cout<<"Array is:";
for(int i=0;i<n;i++)
cout<<a[i]<<"\t";
cout<<"\n";

}
void swap(int &i, int &j)
{
int temp;
temp=i;
i=j;
j=temp;
}
void sort(int a[], int &n)
{
for(int i=0;i<n-1;i++)
{
for(int j=0;j<(n-i-1);j++)
{
if(a[j]>a[j+1])
swap(a[j],a[j+1]);
}
}
}

#OUTPUT
Enter number of elements in array:3
Enter data:
23
12
19
Array is:23 12 19
Array is:12 19 23

➢ Sum of Matrices:

#CODE
#include<iostream>
using namespace std;

class Add
{
public:
void sum(int r,int c)
{
int m1[r][c], m2[r][c], s[r][c];
cout<<"Enter the elements of 1st matrix:\n";
for(int i=0;i<r;i++)
{
for(int j=0;j<c;j++)
cin>>m1[i][j];
}
cout<<"Enter the elements of 2nd matrix:\n";
for(int i=0;i<r;i++)
{
for(int j=0;j<c;j++)
cin>>m2[i][j];
}
cout<<"Sum of Matrices:\n";
for(int i=0;i<r;i++)
{
for(int j=0;j<c;j++)
{
s[i][j]=m1[i][j]+m2[i][j];
cout<<s[i][j]<<" ";
}
cout<<"\n";
}
}
};

int main()
{
int row,col;
cout<<"Enter number of rows(1-10):";
cin>>row;
cout<<"Enter number of columns(1-10):";
cin>>col;
Add obj;
obj.sum(row,col);
return 0;
}

#OUTPUT
Enter number of rows(1-10):3
Enter number of columns(1-10):3
Enter the elements of 1st matrix:
2
5
8
3
9
4
1
6
3
Enter the elements of 2nd matrix:
7
5
9
2
2
4
7
6
8
Sum of Matrices:
9 10 17
5 11 8
8 12 11

You might also like