0% found this document useful (0 votes)
61 views9 pages

Task 2 Dsa Lab

This document contains the details of 4 programming tasks completed by Aiman Fareed with ID 02-235201-045. The tasks include: 1) A program to input 3 integers and output the smallest, 2) A program to input and sort 10 integers in an array, 3) A program to create a student structure and input student details, 4) Performing the previous task using pointers to structures. For each task, the code and output are provided.

Uploaded by

Aiman Fareed
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)
61 views9 pages

Task 2 Dsa Lab

This document contains the details of 4 programming tasks completed by Aiman Fareed with ID 02-235201-045. The tasks include: 1) A program to input 3 integers and output the smallest, 2) A program to input and sort 10 integers in an array, 3) A program to create a student structure and input student details, 4) Performing the previous task using pointers to structures. For each task, the code and output are provided.

Uploaded by

Aiman Fareed
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/ 9

NAME: AIMAN FAREED

ENROLLMENT: 02-235201-045

TASK # 01
Write a Program to enter three integers and output the smallest integer using IF.
CODE:
#include<iostream>

using namespace std;

int main()

int a, b, c;

cout << "Enter the first value a= ";

cin >> a;

cout << "Enter the second value b= ";

cin >> b;

cout << "Enter the second value c= ";

cin >> c;

if (a < b && a < c) {

cout << " a is the smallest value ";

else if (b < a && b<c) {

cout << "b is the smallest value";

else if (c < a && c < b) {

cout << "c is the smallest value";

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>

using namespace std;

int main()

int arr[100];

int size, i, j, temp;

cout << "Enter size of array: ";

cin >> size;

cout << "Enter elements in array: ";


NAME: AIMAN FAREED
ENROLLMENT: 02-235201-045
for (i = 0; i < size; i++)

cin >> arr[i];

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

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

if (arr[j] < arr[i])

temp = arr[i];

arr[i] = arr[j];

arr[j] = temp;

cout << "Elements of array in sorted ascending order:" << endl;

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

cout << arr[i] << endl;

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>

using namespace std;

struct student

char StdName[50];

int StdID;

int StdAge;

} s[1];
NAME: AIMAN FAREED
ENROLLMENT: 02-235201-045
int main()

cout << "Enter information of students: " << endl;

for (int i = 0; i < 10; ++i)

s[i].StdID = i + 1;

cout << " student ID =" << s[i].StdID<< "," << endl;

cout << "Enter Name: ";

cin >> s[i].StdName;

cout << "Enter Age: ";

cin >> s[i].StdAge;

cout << endl;

cout << "Displaying Information: " << endl;

for (int i = 0; i < 10; ++i)

cout << "\nstudent ID: " << i + 1 << endl;

cout << "Name: " << s[i].StdName << endl;

cout << "Age: " << s[i].StdAge << 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];
}
}

cout << "Matrix A: \n ";


for (i = 0; i < row; i++)
{
for (j = 0; j < col; j++)
cout << a[i][j] << " ";

cout << "\n ";


}
cout << "Matrix B : \n ";
for (i = 0; i < row; i++)
{
for (j = 0; j < col; j++)
cout << b[i][j] << " ";

cout << "\n ";


}

cout << "Multiplication of the matrix=\n";


for (i = 0; i < row; i++)
{
for (j = 0; j < col; j++)
{
mul[i][j] = 0;
for (k = 0; k < col; k++)
{
mul[i][j] += a[i][k] * b[k][j];
}
}
}
//for printing result
for (i = 0; i < row; i++)
{
for (j = 0; j < col; j++)
{
cout << mul[i][j] << " ";
}
cout << "\n";
}
cout << "\nAdding the Two Given Matrix...\n";
for (i = 0; i < row; i++)
{
for (j = 0; j < col; j++)
sum[i][j] = a[i][j] + b[i][j];
}
cout << "Addition Result of Two Given Matrix is:\n";
for (i = 0; i < row; i++)
{
for (j = 0; j <col ; j++)
NAME: AIMAN FAREED
ENROLLMENT: 02-235201-045
cout << sum[i][j] << " ";
cout << endl;
}
cout << "\nSubtraction the Two Given Matrix...\n";
for (i = 0; i < row; i++)
{
for (j = 0; j < col; j++)
diff[i][j] = a[i][j] - b[i][j];
}
cout << "Difference of Two Given Matrix is:\n";
for (i = 0; i < row; i++)
{
for (j = 0; j < col; j++)
cout << diff[i][j] << " ";
cout << endl;
}

return 0;
}

OUTPUT:

You might also like