Task 2 Dsa Lab
Task 2 Dsa Lab
ENROLLMENT: 02-235201-045
TASK # 01
Write a Program to enter three integers and output the smallest integer using IF.
CODE:
#include<iostream>
int main()
int a, b, c;
cin >> a;
cin >> b;
cin >> c;
system("pause");
}
NAME: AIMAN FAREED
ENROLLMENT: 02-235201-045
OUTPUT:
TASK # 02
Write a Program to enter 10 integers in a single-dimension array and then print out the array
in ascending order.
CODE:
#include<iostream>
int main()
int arr[100];
temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
return 0;
system("pause");
}
NAME: AIMAN FAREED
ENROLLMENT: 02-235201-045
OUTPUT:
TASK # 03
Write a program to create structure named student. Take information of student from user as
input (StdID, StdName, StdAge etc.) Display the output.
Code:
#include <iostream>
struct student
char StdName[50];
int StdID;
int StdAge;
} s[1];
NAME: AIMAN FAREED
ENROLLMENT: 02-235201-045
int main()
s[i].StdID = i + 1;
cout << " student ID =" << s[i].StdID<< "," << endl;
return 0;
}
NAME: AIMAN FAREED
ENROLLMENT: 02-235201-045
OUTPUT:
TASK # 04
Perform above task using pointers to structure
CODE:
#include<iostream>
using namespace std;
int main()
{
struct stud
{
int age;
char name[15];
float id;
};
stud s1;
cout << "Enter Student Name :" << endl;
cin >> s1.name;
cout << "Enter Student Age :" << endl;
cin >> s1.age;
cout << "Enter Student ID :" << endl;
cin >> s1.id;
struct stud* x;
x = &s1;
cout << "\nStudent's Information" << endl;
cout << "Name :" << (*x).name << endl;
cout << "Age :" << (*x).age << endl;
cout << "ID :" << (*x).id << endl;
NAME: AIMAN FAREED
ENROLLMENT: 02-235201-045
system("pause");
return 0;
}
Output:
1. Write a program which input 2 matrix of user defined rows and columns and perform
following operation
a. Display/Print as a Matrix
b. Addition of Matrix
c. Subtraction of Matrix
d. matrix multiplication
CODE:
#include <iostream>
using namespace std;
int main()
{
int a[10][10], b[10][10], mul[10][10],sum[10][10] , diff[10][10],row, col, i, j, k;
cout << "Enter the number of Row=";
cin >> row;
cout << "Enter the number of Column=";
cin >> col;
cout << "Enter the first matrix element=\n";
for (i = 0; i < row; i++)
{
for (j = 0; j < col; j++)
NAME: AIMAN FAREED
ENROLLMENT: 02-235201-045
{
cin >> a[i][j];
}
}
cout << "Enter the second matrix element=\n";
for (i = 0; i < row; i++)
{
for (j = 0; j < col; j++)
{
cin >> b[i][j];
}
}
return 0;
}
OUTPUT: