0% found this document useful (0 votes)
13 views11 pages

Lab 11

C++ arrays

Uploaded by

rayyanquddusi683
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)
13 views11 pages

Lab 11

C++ arrays

Uploaded by

rayyanquddusi683
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/ 11

Task: 1

Code:
#include<iostream>
using namespace std ;
const int MAX = 5;
void input_matrix(float A[][MAX] , int r , int c);
void output_matrix(float A[][MAX] , int r , int c);
int main ()
{
float A[MAX][MAX] , B[MAX][MAX];
int r , c;
cout<<"Enter dimensions of A "<<endl;
cin>>r>>c;
input_matrix( A , r , c);
cout<<endl;
output_matrix( A , r , c);
cout<<endl;
for (int i=0 ; i<c; i++)
{
for (int j=0 ; j<r; j++)
{
B[i][j] = A[j][i];
}
}
for (int i=0 ; i<c; i++)
{
for (int j=0 ; j<r; j++)
{
B[i][j] =-1 *B[i][j];
}
}
// Check matrix ;
bool flag=true ;
for (int i=0 ; i<c; i++)
{
for (int j=0 ; j<r; j++)
{
if (B[i][j]!=A[i][j])
{
cout<<"Matrix is not skew symetric";
flag = false;
break;
}
if (flag==0)
{
break;
}
}
}

if (flag)
{
cout<<"Hence matrix is skew symmteric it's negative transpose is equal to user matrix"<<endl;
output_matrix(B , r , c) ;
}
}
void input_matrix(float A[][MAX] , int r , int c)
{
for (int i=0 ; i<r ; i++)
{
for (int j=0 ; j<c ; j++)
{
cout<<"Enter element ["<<i+1<<"]["<<j+1<<"]";
cin>>A[i][j];
}
}
}
void output_matrix(float A[][MAX] , int r , int c)
{
for (int i=0 ; i<r ; i++)
{
for (int j=0 ; j<c ; j++)
{
cout<<A[i][j]<<" ";
}
cout<<endl;
}

OUTPUT:

TASK:2
CODE:
#include<iostream>
using namespace std ;
const int MAX = 5;
void input_matrix(float A[][MAX] , int r , int c);
void output_matrix(float A[][MAX] , int r , int c);
void search_num(float A[][MAX] , int r , int c , float n );
int main ()
{
float A[MAX][MAX] ;
int r , c , n;
cout<<"Enter dimensions of A "<<endl;
cin>>r>>c;

input_matrix( A , r , c);
cout<<endl;
output_matrix( A , r , c);
cout<<endl;
cout<<"Enter element to search ";
cin>>n;
search_num( A, r , c , n );
}
void input_matrix(float A[][MAX] , int r , int c)
{
for (int i=0 ; i<r ; i++)
{
for (int j=0 ; j<c ; j++)
{
cout<<"Enter element ["<<i+1<<"]["<<j+1<<"]";
cin>>A[i][j];
}
}
}

void output_matrix(float A[][MAX] , int r , int c)


{
for (int i=0 ; i<r ; i++)
{
for (int j=0 ; j<c ; j++)
{
cout<<A[i][j]<<" ";
}
cout<<endl;
}

}
void search_num(float A[][MAX] , int r , int c , float n )
{
bool flag = true ;
int rows = -1 , col = -1 ;
for (int i=0 ; i<r ; i++)
{
for ( int j=0 ; j<c ; j++)
{
if (A[i][j]==n)
{
rows = i ;
col = j;
cout<<"Dimension of element is ["<<rows+1<<"]["<<col+1<<"]";
flag = false ;
cout<<endl;
}
}
}
if (flag)
{
cout<<"Element is not found"<<endl;
cout<<rows<<" "<<col;
}
}

OUTPUT:
Task:3
Code:
#include<iostream>
using namespace std ;
const int MAX = 5;
void input_matrix(float A[][MAX] , int r , int c);
void output_matrix(float A[][MAX] , int r , int c);

int main ()
{
float A[MAX][MAX] ;
int r , c ;
cout<<"Enter dimensions of A "<<endl;
cin>>r>>c;

input_matrix( A , r , c);
cout<<endl;
output_matrix( A , r , c);
cout<<endl;
for (int i=0 ; i<r ; i++)
{
for (int j=0 ; j<c ; j++)
{
if (i>j)
{
A[i][j] = 0 ;
}
}
}
cout<<"Lower triangular form of matrix is: "<<endl;
output_matrix( A , r , c);
for (int i=0 ; i<r ; i++)
{
for (int j=0 ; j<c ; j++)
{
if (i<j)
{
A[i][j] = 0 ;
}
}
}
cout<<endl<<"Upper triangular form of matrix is: "<<endl;
output_matrix( A , r , c);

}
void input_matrix(float A[][MAX] , int r , int c)
{
for (int i=0 ; i<r ; i++)
{
for (int j=0 ; j<c ; j++)
{
cout<<"Enter element ["<<i+1<<"]["<<j+1<<"]";
cin>>A[i][j];
}
}
}

void output_matrix(float A[][MAX] , int r , int c)


{
for (int i=0 ; i<r ; i++)
{
for (int j=0 ; j<c ; j++)
{
cout<<A[i][j]<<" ";
}
cout<<endl;
}

OUTPUT:
Task: 4
Code:
#include<iostream>
#include<cstring>
using namespace std;

void Input(char name[100]);


void Conc(char A[100], char B[100], char C[100], char D[500]);

int main() {
char A[100], B[100], C[100], D[500] = "";
Input(A);
Input(B);
Input(C);
Conc(A, B, C, D);
cout << "The concatenated form of these three strings is: " << D << endl;

return 0;
}

void Input(char name[100]) {


cout << "Enter a string: ";
cin.getline(name, 100);
}

void Conc(char A[100], char B[100], char C[100], char D[500])


{
strcpy(D, A);
strcat(D, B);
strcat(D, C);
}

OUTPUT:
Computer Fundamental and Programming
CIS-101
Fall 2024
Lab Report no.
Obtained Marks
Total Marks

Lab Engineer Signature &


Comments

Student Name
Rayyan Quddusi

Section: B
Experiment No: 11 Date of Submission:
24-12-24
Experiment Title:
2-D arrays along with strings
Batch: Teacher:
BSEE 2024-28 Dr. Muhammad Tufail
Semester Lab Engineer:
1st Mr. Adam Abbas
Mr. M Hunzilah Ahmad

Department of Electrical Engineering

You might also like