LT02
LT02
Technology
COMPUTER SCIENCE DEPARTMENT
DSA (Lab)
Lab Task #02
Lab Task # 1
Write a C++ program to find the two repeating elements in a given array of integers.
Code:
#include <iostream>
int main()
int arr[5];
cin>>arr[i];
if(arr[i]==arr[j])
cout<<" "<<arr[i];
return 0;
Output:
Lab Task # 2
Take 20 integer inputs from user and print the following:
Number of 0.
Code:
#include <iostream>
DSA-Lab BSSE-3B SZABIST-ISB
S haheed Zulfikar Ali Bhutto Institute of Science &
usingTechnology
namespace std;
int main()
{
int integer[10];
cout<<"Enter 10 Integers "<<endl;
if (integer[i] % 2 == 0)
{
cout<<"The Number is Even "<<integer[i]<<endl;
}
else
{
cout<<"The Number is odd "<<integer[i]<<endl;
}
}
return 0;
}
Output:
Lab Task # 3
Write a C++ program to find second largest element in a given array of integers.
Code:
#include <iostream>
using namespace std;
int main()
{
int arr[5];
int largest,smallest;
if(arr[0]<arr[1])
{
largest = arr[1];
smallest = arr[0];
}
else
DSA-Lab BSSE-3B SZABIST-ISB
S haheed Zulfikar Ali Bhutto Institute of Science &
{
Technology
largest = arr[0];
smallest = arr[1];
smallest = arr[i];
}
Output:
Code:
#include <iostream>
using namespace std;
int main()
{
int mat1[2][2];
int mat2[2][2];
int sum[2][2];
Lab Task # 5
Write a program Multiply Two Matrices using Multi-dimensional Arrays.
Code:
#include <iostream>
using namespace std;
int main()
{
int mat1[2][2];
int mat2[2][2];
int c[2][2];
cout<<"Enter 1st Matix of 2x2 "<<endl;
}
DSA-Lab BSSE-3B SZABIST-ISB
S haheed Zulfikar Ali Bhutto Institute of Science &
Technology
cout<<"Enter 2nd Matix of 2x2 "<<endl;
int sum = 0;
for(int i = 0 ; i < 2 ; i++)
{
for(int j = 0 ; j < 2 ; j++)
{
for(int k = 0 ; k < 2 ; k++)
{
}
c[i][j] = sum;
sum = 0;
}
}
cout<<"Multiplication of matrix is: \n";
for(int i = 0 ; i < 2 ; i++)
{
for(int j = 0 ; j < 2 ; j++)
{
cout<<" "<<c[i][j];
}
cout<<"\n";
}
}
Output: