0% found this document useful (0 votes)
16 views

23 CS 05

DSA

Uploaded by

moazbinzafar2
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)
16 views

23 CS 05

DSA

Uploaded by

moazbinzafar2
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/ 12

SUMMITED

TO:
Sir Faheem

SMMITED BY:
MOAZ Bin
ZAFAR
(23-CS-05)

PROGRAMING FUNDAMENTAL
ASSIGNMENT#1
TASK#1
#include<iostream>

using namespace std;

int main(){

int i,n,product;

cout<<"MOAZ BIN ZAFAR"<<"23-CS-05";

cout<<"Enter number"<<endl;

cin>>n;

for(i=1;i<=10;i++){

product=n*i;

cout<<product<<" ";

cout<<"\n";

for(i=11;i<=20;i++){

product=n*i;

cout<<product<<" ";

cout<<"\n";

for(i=21;i<=30;i++){

product=n*i;

cout<<product<<" ";

}
Task#2
#include<iostream>

using namespace std;

int main(){

cout<<"MOAZ BIN ZAFAR"<<"23-CS-05";

cout<<"Enter number"<<endl;

int N1,N2,N3,a;

cout<<"Enter 3 number"<<endl;

cin>>N1>>N2>>N3;

if(N1%2==0){

cout<<N1<<" is even"<<endl;

}else{

cout<<N1<<" ODD"<<endl;

if(N2%2==0){

cout<<N2<<" is even"<<endl;

}else{

cout<< N2<<" ODD"<<endl;

if(N3%2==0){

cout<<N3<<" is even"<<endl;

}else{

cout<<N3<<" ODD"<<endl;

if(N2<N1&&N1>N3){

cout<<"N1 is greater"<<endl;

}else if(N1<N2&&N2>N3){

cout<<"N2 is greater"<<endl;

}
else if(N2<N3&&N3>N1){

cout<<"N3 is greater";

Tsk#3
#include<iostream>

using namespace std;

int main(){

int n,i,count=0;

cout<<"MOAZ BIN ZAFAR\n";

cout<<"23-cs-5\n";

cout<<"Enter number"<<endl;

cin>>n;

for(i=2;i<n;i++){

if(n%i==0){

count++;

break;

}
}

if(count==0){

cout<<"prime";

}else{

cout<<"Composite";

return 0;

Task#4
#include<iostream>

using namespace std;

void Fibonacci(int n) { int fib_array[n];

fib_array[0] = 0;

fib_array[1] = 1;

for (int i = 2; i < n; i++) {

fib_array[i] = fib_array[i - 1] + fib_array[i - 2];

cout << "Fibonacci Series up to " << n << ": "; for (int i = 0; i < n; i++) {

cout << fib_array[i] << " ";

cout << endl;

}
int main() { int n;

cout<<"Moaz bin zafar 23-CS-05:"<<endl;

cout << "Enter the number of Fibonacci series elements: \n"; cin >> n;

if (n <= 0) {

cout << "Invalid input. Please enter a positive integer.\n" << endl; return 1;

Fibonacci(n); return 0;

Task#6
#include <iostream>

using namespace std;

int main() {

cout<<"Moaz bin zafar 23-cs-05:"<<endl;

int n;

cout << "Enter the number of rows for the pyramid: "<<endl;

cin >> n;

for (int i = 1; i <= n; i++) {

for (int j = 1; j <= n- i; j++)

cout << " ";

for (int k = 1; k <= 2 * i - 1; k++)

{ cout << "*";

}
cout << endl;

return 0;}

Task#5
#include<iostream>

using namespace std;

const int MAX_SIZE = 100;

void inputMatrix(int matrix[MAX_SIZE][MAX_SIZE], int rows, int cols) {

cout << "Enter the matrix elements:" << endl; for (int i = 0; i < rows; i++) {

for (int j = 0; j < cols; j++) {

cout << "Element at position (" << i + 1 << ", " << j + 1 << "): ";

cin >> matrix[i][j];

}}}

void multiplyMatrices(int result[MAX_SIZE][MAX_SIZE], int matrix1[MAX_SIZE][MAX_SIZE], int


matrix2[MAX_SIZE][MAX_SIZE], int rows1, int cols1, int rows2, int cols2) {

for (int i = 0; i < rows1; i++) { for (int j = 0; j < cols2; j++) {

result[i][j] = 0;

for (int k = 0; k < cols1; k++) {

result[i][j] += matrix1[i][k] * matrix2[k][j];}

}}}

void displayMatrix(int matrix[MAX_SIZE][MAX_SIZE], int rows, int cols) {

cout << "Resultant Matrix:" << endl; for (int i = 0; i < rows; i++) {
for (int j = 0; j < cols; j++)

{ cout << matrix[i][j] << " ";

cout << endl;

}}

int main() {

cout<<"Moaz 23-cs-05 "<<endl;

int matrix1[MAX_SIZE][MAX_SIZE], matrix2[MAX_SIZE][MAX_SIZE], result[MAX_SIZE][MAX_SIZE];

int rows1, cols1, rows2, cols2;

cout << "Enter dimensions of the first matrix (rows columns): ";

cin >> rows1 >> cols1;

inputMatrix(matrix1, rows1, cols1);

cout << "Enter dimensions of the second matrix (rows columns): ";

cin >> rows2 >> cols2;

inputMatrix(matrix2, rows2, cols2);

if (cols1 != rows2) {

cout << "Matrices cannot be multiplied. Number of columns in the first matrix should be equal to the
number of rows in the second matrix." << endl;

return 1;

multiplyMatrices(result, matrix1, matrix2, rows1, cols1, rows2, cols2);

displayMatrix(result, rows1, cols2);

return 0;

}}
Task#7
#include<iostream>

#include<algorithm>

using namespace std;

int main() {

int n;

cout<<"Moaz Bin Zafar 23-CS-05:"<<endl;

cout << "Enter the size of the array: "<<endl;

cin >> n;

if (n <= 0) {

cout << "Invalid input!" << endl; return 1;

int arr[n];

cout << "Enter the array elements:" << endl; for (int i = 0; i < n; i++) {

cout << "Element " << i + 1 << ": ";

cin >> arr[i];


}

int maxElement = *max_element(arr, arr + n);

int minElement = *min_element(arr, arr + n);

cout << "Maximum value: " << maxElement << endl; cout << "Minimum value: " << minElement <<
endl;

return 0;

Task#8
#include<iostream>

#include<string>

#include<cctype>

using namespace std;

int checkstrength(const string& password) { int lengthScore = 0;

int numberScore = 0;

int specialCharScore = 0;

int upperCaseScore = 0;
int lowerCaseScore = 0;

if (password.length() >= 8) { lengthScore = 2;

} else if (password.length() >= 6) { lengthScore = 1;

for (size_t i = 0; i < password.length(); i++)

if (isdigit(password[i])) {

numberScore = 2; break;

} }

for (size_t i = 0; i < password.length(); i++)

if (!isalnum(password[i])) {

specialCharScore = 2; break;

} }

for (size_t i = 0; i < password.length(); i++)

{ if

(isupper(password[i])) {

upperCaseScore = 2; break;

} }

for (size_t i = 0; i < password.length(); i++)

if (islower(password[i])) {

lowerCaseScore = 2; break;

} }

int totalScore = lengthScore + numberScore + specialCharScore + upperCaseScore + lowerCaseScore;

return totalScore;

int main() {

string password;

cout<<"Moaz bin zafar 23-cs-05"<<endl; cout << "Enter your password: ";

getline(cin, password);
int strengthScore = checkstrength(password);

cout << "Password Strength Score: " << strengthScore << "/10" <<

endl;

--------------------------------------------------------------------------------------------------------------------

You might also like