SlideShare a Scribd company logo
1 of 19
Download to read offline
17Jan2023: 2D Arrays: Matrix operations
PROGRAMMING FOR
PROBLEM SOLVING (PPS)
B.Tech I Sem CST
Multidimensional arrays
 One dimensional array:
 int oneD[size1];
 Two dimensional array:
 int twoD[size1][size2];
 Three dimensional array:
 int threeD[size1] [size2] [size2];
 N dimensional array:
 int multiD[size1]…[sizen]; Dr. C. Sreedhar
2D Array
int arr2d[size1][size2]; int disp[2][4] = {
{10, 11, 12, 13},
{14, 15, 16, 17}
};
int disp[2][4] =
{ 10, 11, 12, 13, 14, 15, 16, 17};
int abc[][2] = {1, 2, 3 ,4 } // Valid
int abc[][] = {1, 2, 3 ,4 } // Invalid
int abc[2][] = {1, 2, 3 ,4 } // Invalid
Dr. C. Sreedhar
Accept 2d elements and display
int disp[2][3];
for(i=0; i<2; i++)
{
for(j=0;j<3;j++)
{
printf("Enter disp[%d][%d]:", i, j);
scanf("%d", &disp[i][j]);
}
}
for(i=0; i<2; i++)
{
for(j=0;j<3;j++)
{ printf("%d ", disp[i][j]); if(j==2) printf("n"); }
}
Dr. C. Sreedhar
Dr. C. Sreedhar
Matrix operations: addition
int r,c,i,j,A[10][10], B[10][10], Sum[10][10];
scanf("%d %d",&r,&c);
for(i = 0; i < r; i++)
{
for(j = 0; j < c; j++)
scanf("%d",&A[i][j]);
}
for (i = 0; i < r; i++)
{
for (j = 0; j < c; j++)
{
Sum[i][j] = A[i][j] + B[i][j];
printf("%dt", Sum[i][j]);
}
printf("n");
}
for(i = 0; i < r; i++)
{
for(j = 0; j < c; j++)
scanf("%d",&B[i][j]);
}
Dr. C. Sreedhar
int m, n, p, q, i, j, k;
int a[10][10], b[10][10], res[10][10];
scanf("%d%d", & m, & n); // first matrix size
scanf("%d%d", & p, & q); // second matrix size
if (n != p)
printf("Matrix is incompatible for multiplicationn");
else
{
for (i = 0; i < m; i++)
{
for (j = 0; j < n; j++) scanf("%d", & a[i][j]);
}
for (i = 0; i < p; i++)
{
for (j = 0; j < q; j++) scanf("%d", & b[i][j]);
}
Matrix Mult
Dr.
C.
Sreedhar
for (i = 0; i < m; i++)
{
for (j = 0; j < q; j++)
{
res[i][j] = 0;
for (k = 0; k < p; k++) res[i][j] += a[i][k] * b[k][j];
}
}
for (i = 0; i < m; i++)
{
for (j = 0; j < q; j++) printf("%dt", res[i][j]);
printf("n");
}
}
Matrix Mult
Dr.
C.
Sreedhar
pass two-dimensional arrays to function
void Function(int c[2][2]);
int main()
{
int c[2][2],i,j;
printf("Enter 4 numbers:n");
for(i=0;i<2;++i)
for(j=0;j<2;++j) {
scanf("%d",&c[i][j]);
}
Function(c);
return 0;
}
Enter 4
numbers:
2
3
4
5
Displaying:
2
3
4
5
void Function(int c[2][2])
{
int i,j;
printf("Displaying:n");
for(i=0;i<2;++i)
for(j=0;j<2;++j)
printf("%dn",c[i][j]);
}
Dr. C. Sreedhar
Matrix Mult: UDF
Input(a,m,n);
Input(b,p,q);
display(a,m,n);
display(b,p,q);
multiply(a,b,c,m,n,p,q);
display(c,m,q);
void input(int a[][10], int m, int n)
{
int i, j;
printf("nEnter matr.elements:");
for (i = 0; i < m; ++i)
{
for (j = 0; j < n; ++j)
scanf("%d", & a[i][j]);
}
}
Dr. C. Sreedhar
Matrix Mult: UDF
Input(a,m,n);
Input(b,p,q);
display(a,m,n);
display(b,p,q);
multiply(a,b,c,m,n,p,q);
display(c,m,q);
void display(int a[][10], int m,int n)
{
int i, j;
for (i = 0; i < m; i++)
{
for (j = 0; j < n; j++)
printf("%d", a[i][j]);
printf("n")
}
}
Dr. C. Sreedhar
Matrix Mult: UDF
Input(a,m,n);
Input(b,p,q);
display(a,m,n);
display(b,p,q);
multiply(a,b,c,m,n,p,q);
display(c,m,q);
void multiply(int a[][10], int b[][10],
int c[][10], int m, int n, int p, int q)
{
int i, j, k;
for (i = 0; i < m; ++i)
{
for (j = 0; j < q; ++j) c[i][j] = 0;
}
for (i = 0; i < m; ++i)
{
for (j = 0; j < q; ++j)
{
for (k = 0; k < n; ++k)
c[i][j] += a[i][k] * b[k][j];
}
}
}
Dr. C. Sreedhar
for (int i = 0; i < r; ++i)
for (int j = 0; j < c; ++j)
scanf("%d", &a[i][j]);
for (int i = 0; i < r; ++i)
for (int j = 0; j < c; ++j)
transpose[j][i] = a[i][j];
for (int i = 0; i < c; ++i)
for (int j = 0; j < r; ++j)
{
printf("%d ", transpose[i][j]);
if (j == r - 1) printf("n");
}
Matrix Transpose
Dr.
C.
Sreedhar
int matrix[3][3],sum = 0;
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
if(i == j) sum += matrix[i][j];
}
}
for(int i=0; i<3; i++) {
for(int j=0; j<3; j++)
printf("%d ", matrix[i][j]);
printf("n");
}
printf("Sum of diagonal elements = %dn", sum);
Sum of diagonal elements of matrix
Dr.
C.
Sreedhar
MultiDim.Array: Declaration, Initialization, Accessing
 Syntax: datatype arrname[size1][size2]...[sizeN];
 Declaration: int threeD[2][3][4];
 Initialization:
 int arr[3][2][2]={0,1,2,3,4,5,6,7,8,9,3,2};
 int arr[3][3][3]=
{ { {10,20,30},{40,50,60},{70,80,90} },
{ {11,22,33},{44,55,66},{77,88,99} },
{ {12,23,34},{45,56,67},{78,89,90} }
}; Dr. C. Sreedhar
arr[3][3] =
[ a00, a01, a02 ]
[ b10, b11, b12 ]
[ c20, c21, c22 ]
Row major order = a00, a01, a02, b10, b11, b12, c20, c12, c22
Column major order = a00, b10, c20, a01, b11, c21, a02, b12, c22
Command line arguments
 There are 2 components of Command Line Argument in C:
 argc:
 refers to “argument count”. It is the first parameter that we use to store
the number of command line arguments.
 value of argc should be greater than or equal to 0.
 agrv:
 refers to “argument vector”. It is basically an array of character pointer
to list all the command line arguments.
Dr. C. Sreedhar
#include<stdio.h>
int main(int argc, char** argv)
{
printf("Welcome to PPSn");
int i;
printf("The number of arguments are: %dn",argc);
printf("The arguments are:");
for ( i = 0; i < argc; i++)
{
printf("%sn", argv[i]);
}
return 0;
} Dr. C. Sreedhar
int main( int argc, char *argv[] )
{
if( argc == 2 ) {
printf("The argument supplied is %sn", argv[1]);
}
else if( argc > 2 ) {
printf("Too many arguments supplied.n");
}
else {
printf("One argument expected.n");
}
}
Dr. C. Sreedhar

More Related Content

What's hot

C Recursion, Pointers, Dynamic memory management
C Recursion, Pointers, Dynamic memory managementC Recursion, Pointers, Dynamic memory management
C Recursion, Pointers, Dynamic memory managementSreedhar Chowdam
 
Handling of character strings C programming
Handling of character strings C programmingHandling of character strings C programming
Handling of character strings C programmingAppili Vamsi Krishna
 
Tail Recursion in data structure
Tail Recursion in data structureTail Recursion in data structure
Tail Recursion in data structureRumman Ansari
 
Function in c program
Function in c programFunction in c program
Function in c programumesh patil
 
Pointers in c - Mohammad Salman
Pointers in c - Mohammad SalmanPointers in c - Mohammad Salman
Pointers in c - Mohammad SalmanMohammadSalman129
 
Python Programming Strings
Python Programming StringsPython Programming Strings
Python Programming StringsSreedhar Chowdam
 
Programming For Problem Solving Lecture Notes
Programming For Problem Solving Lecture NotesProgramming For Problem Solving Lecture Notes
Programming For Problem Solving Lecture NotesSreedhar Chowdam
 
Let us C (by yashvant Kanetkar) chapter 3 Solution
Let us C   (by yashvant Kanetkar) chapter 3 SolutionLet us C   (by yashvant Kanetkar) chapter 3 Solution
Let us C (by yashvant Kanetkar) chapter 3 SolutionHazrat Bilal
 
Managing input and output operation in c
Managing input and output operation in cManaging input and output operation in c
Managing input and output operation in cyazad dumasia
 
Strings in c
Strings in cStrings in c
Strings in cvampugani
 
Expression and Operartor In C Programming
Expression and Operartor In C Programming Expression and Operartor In C Programming
Expression and Operartor In C Programming Kamal Acharya
 
C programming language tutorial
C programming language tutorial C programming language tutorial
C programming language tutorial javaTpoint s
 
Introduction to cpp
Introduction to cppIntroduction to cpp
Introduction to cppNilesh Dalvi
 

What's hot (20)

C Recursion, Pointers, Dynamic memory management
C Recursion, Pointers, Dynamic memory managementC Recursion, Pointers, Dynamic memory management
C Recursion, Pointers, Dynamic memory management
 
Handling of character strings C programming
Handling of character strings C programmingHandling of character strings C programming
Handling of character strings C programming
 
Tail Recursion in data structure
Tail Recursion in data structureTail Recursion in data structure
Tail Recursion in data structure
 
Function in c program
Function in c programFunction in c program
Function in c program
 
Pointers in c - Mohammad Salman
Pointers in c - Mohammad SalmanPointers in c - Mohammad Salman
Pointers in c - Mohammad Salman
 
Python Programming Strings
Python Programming StringsPython Programming Strings
Python Programming Strings
 
Programming For Problem Solving Lecture Notes
Programming For Problem Solving Lecture NotesProgramming For Problem Solving Lecture Notes
Programming For Problem Solving Lecture Notes
 
Let us C (by yashvant Kanetkar) chapter 3 Solution
Let us C   (by yashvant Kanetkar) chapter 3 SolutionLet us C   (by yashvant Kanetkar) chapter 3 Solution
Let us C (by yashvant Kanetkar) chapter 3 Solution
 
functions of C++
functions of C++functions of C++
functions of C++
 
Basics of c++
Basics of c++Basics of c++
Basics of c++
 
Functions in C
Functions in CFunctions in C
Functions in C
 
Managing input and output operation in c
Managing input and output operation in cManaging input and output operation in c
Managing input and output operation in c
 
C++ programming function
C++ programming functionC++ programming function
C++ programming function
 
Introduction to C++
Introduction to C++Introduction to C++
Introduction to C++
 
Pointers
PointersPointers
Pointers
 
Strings in c
Strings in cStrings in c
Strings in c
 
Expression and Operartor In C Programming
Expression and Operartor In C Programming Expression and Operartor In C Programming
Expression and Operartor In C Programming
 
C programming language tutorial
C programming language tutorial C programming language tutorial
C programming language tutorial
 
Strings in c++
Strings in c++Strings in c++
Strings in c++
 
Introduction to cpp
Introduction to cppIntroduction to cpp
Introduction to cpp
 

Similar to PPS Arrays Matrix operations

Similar to PPS Arrays Matrix operations (20)

11 1. multi-dimensional array eng
11 1. multi-dimensional array eng11 1. multi-dimensional array eng
11 1. multi-dimensional array eng
 
array2d.ppt
array2d.pptarray2d.ppt
array2d.ppt
 
ماترێکس به‌ کوردی ئارام
ماترێکس به‌ کوردی ئارامماترێکس به‌ کوردی ئارام
ماترێکس به‌ کوردی ئارام
 
C programs
C programsC programs
C programs
 
C lab excellent
C lab excellentC lab excellent
C lab excellent
 
C and Data Structures Lab Solutions
C and Data Structures Lab SolutionsC and Data Structures Lab Solutions
C and Data Structures Lab Solutions
 
C and Data Structures
C and Data Structures C and Data Structures
C and Data Structures
 
2D array
2D array2D array
2D array
 
C Programming Language Part 8
C Programming Language Part 8C Programming Language Part 8
C Programming Language Part 8
 
C arrays
C arraysC arrays
C arrays
 
Vcs16
Vcs16Vcs16
Vcs16
 
computer Science project.pdf
 computer Science project.pdf computer Science project.pdf
computer Science project.pdf
 
Srinivas Reddy Amedapu, CPDS, CP Lab, JNTU Hyderabad
Srinivas Reddy Amedapu, CPDS, CP Lab, JNTU HyderabadSrinivas Reddy Amedapu, CPDS, CP Lab, JNTU Hyderabad
Srinivas Reddy Amedapu, CPDS, CP Lab, JNTU Hyderabad
 
Srinivas Reddy Amedapu C and Data Structures JNTUH Hyderabad
Srinivas Reddy Amedapu C and Data Structures JNTUH HyderabadSrinivas Reddy Amedapu C and Data Structures JNTUH Hyderabad
Srinivas Reddy Amedapu C and Data Structures JNTUH Hyderabad
 
Java arrays
Java    arraysJava    arrays
Java arrays
 
Programming Fundamentals Arrays and Strings
Programming Fundamentals   Arrays and Strings Programming Fundamentals   Arrays and Strings
Programming Fundamentals Arrays and Strings
 
Arrays
ArraysArrays
Arrays
 
A scrupulous code review - 15 bugs in C++ code
A scrupulous code review - 15 bugs in C++ codeA scrupulous code review - 15 bugs in C++ code
A scrupulous code review - 15 bugs in C++ code
 
DSC program.pdf
DSC program.pdfDSC program.pdf
DSC program.pdf
 
Array
ArrayArray
Array
 

More from Sreedhar Chowdam

Design and Analysis of Algorithms Lecture Notes
Design and Analysis of Algorithms Lecture NotesDesign and Analysis of Algorithms Lecture Notes
Design and Analysis of Algorithms Lecture NotesSreedhar Chowdam
 
Design and Analysis of Algorithms (Knapsack Problem)
Design and Analysis of Algorithms (Knapsack Problem)Design and Analysis of Algorithms (Knapsack Problem)
Design and Analysis of Algorithms (Knapsack Problem)Sreedhar Chowdam
 
DCCN Network Layer congestion control TCP
DCCN Network Layer congestion control TCPDCCN Network Layer congestion control TCP
DCCN Network Layer congestion control TCPSreedhar Chowdam
 
Data Communication and Computer Networks
Data Communication and Computer NetworksData Communication and Computer Networks
Data Communication and Computer NetworksSreedhar Chowdam
 
Data Communication & Computer Networks
Data Communication & Computer NetworksData Communication & Computer Networks
Data Communication & Computer NetworksSreedhar Chowdam
 
Python Programming: Lists, Modules, Exceptions
Python Programming: Lists, Modules, ExceptionsPython Programming: Lists, Modules, Exceptions
Python Programming: Lists, Modules, ExceptionsSreedhar Chowdam
 
Python Programming by Dr. C. Sreedhar.pdf
Python Programming by Dr. C. Sreedhar.pdfPython Programming by Dr. C. Sreedhar.pdf
Python Programming by Dr. C. Sreedhar.pdfSreedhar Chowdam
 
Data Structures Notes 2021
Data Structures Notes 2021Data Structures Notes 2021
Data Structures Notes 2021Sreedhar Chowdam
 
Computer Networks Lecture Notes 01
Computer Networks Lecture Notes 01Computer Networks Lecture Notes 01
Computer Networks Lecture Notes 01Sreedhar Chowdam
 
Dbms university library database
Dbms university library databaseDbms university library database
Dbms university library databaseSreedhar Chowdam
 
Er diagram for library database
Er diagram for library databaseEr diagram for library database
Er diagram for library databaseSreedhar Chowdam
 

More from Sreedhar Chowdam (20)

Design and Analysis of Algorithms Lecture Notes
Design and Analysis of Algorithms Lecture NotesDesign and Analysis of Algorithms Lecture Notes
Design and Analysis of Algorithms Lecture Notes
 
Design and Analysis of Algorithms (Knapsack Problem)
Design and Analysis of Algorithms (Knapsack Problem)Design and Analysis of Algorithms (Knapsack Problem)
Design and Analysis of Algorithms (Knapsack Problem)
 
DCCN Network Layer congestion control TCP
DCCN Network Layer congestion control TCPDCCN Network Layer congestion control TCP
DCCN Network Layer congestion control TCP
 
Data Communication and Computer Networks
Data Communication and Computer NetworksData Communication and Computer Networks
Data Communication and Computer Networks
 
DCCN Unit 1.pdf
DCCN Unit 1.pdfDCCN Unit 1.pdf
DCCN Unit 1.pdf
 
Data Communication & Computer Networks
Data Communication & Computer NetworksData Communication & Computer Networks
Data Communication & Computer Networks
 
Big Data Analytics Part2
Big Data Analytics Part2Big Data Analytics Part2
Big Data Analytics Part2
 
Python Programming: Lists, Modules, Exceptions
Python Programming: Lists, Modules, ExceptionsPython Programming: Lists, Modules, Exceptions
Python Programming: Lists, Modules, Exceptions
 
Python Programming by Dr. C. Sreedhar.pdf
Python Programming by Dr. C. Sreedhar.pdfPython Programming by Dr. C. Sreedhar.pdf
Python Programming by Dr. C. Sreedhar.pdf
 
Python Programming
Python Programming Python Programming
Python Programming
 
Big Data Analytics
Big Data AnalyticsBig Data Analytics
Big Data Analytics
 
Data Structures Notes 2021
Data Structures Notes 2021Data Structures Notes 2021
Data Structures Notes 2021
 
Computer Networks Lecture Notes 01
Computer Networks Lecture Notes 01Computer Networks Lecture Notes 01
Computer Networks Lecture Notes 01
 
Dbms university library database
Dbms university library databaseDbms university library database
Dbms university library database
 
Er diagram for library database
Er diagram for library databaseEr diagram for library database
Er diagram for library database
 
Dbms ER Model
Dbms ER ModelDbms ER Model
Dbms ER Model
 
DBMS Notes: DDL DML DCL
DBMS Notes: DDL DML DCLDBMS Notes: DDL DML DCL
DBMS Notes: DDL DML DCL
 
GPREC DBMS Notes 1
GPREC DBMS Notes 1GPREC DBMS Notes 1
GPREC DBMS Notes 1
 
Computer Networks Unit 5
Computer Networks Unit 5Computer Networks Unit 5
Computer Networks Unit 5
 
Jp notes
Jp notesJp notes
Jp notes
 

Recently uploaded

(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Serviceranjana rawat
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Christo Ananth
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
Analog to Digital and Digital to Analog Converter
Analog to Digital and Digital to Analog ConverterAnalog to Digital and Digital to Analog Converter
Analog to Digital and Digital to Analog ConverterAbhinavSharma374939
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Dr.Costas Sachpazis
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Dr.Costas Sachpazis
 
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINESIVASHANKAR N
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130Suhani Kapoor
 
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...srsj9000
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024hassan khalil
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSSIVASHANKAR N
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations120cr0395
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxupamatechverse
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSCAESB
 

Recently uploaded (20)

Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCRCall Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
 
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
 
Analog to Digital and Digital to Analog Converter
Analog to Digital and Digital to Analog ConverterAnalog to Digital and Digital to Analog Converter
Analog to Digital and Digital to Analog Converter
 
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptxExploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
 
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
 
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations
 
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptx
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentation
 

PPS Arrays Matrix operations

  • 1. 17Jan2023: 2D Arrays: Matrix operations PROGRAMMING FOR PROBLEM SOLVING (PPS) B.Tech I Sem CST
  • 2. Multidimensional arrays  One dimensional array:  int oneD[size1];  Two dimensional array:  int twoD[size1][size2];  Three dimensional array:  int threeD[size1] [size2] [size2];  N dimensional array:  int multiD[size1]…[sizen]; Dr. C. Sreedhar
  • 3. 2D Array int arr2d[size1][size2]; int disp[2][4] = { {10, 11, 12, 13}, {14, 15, 16, 17} }; int disp[2][4] = { 10, 11, 12, 13, 14, 15, 16, 17}; int abc[][2] = {1, 2, 3 ,4 } // Valid int abc[][] = {1, 2, 3 ,4 } // Invalid int abc[2][] = {1, 2, 3 ,4 } // Invalid Dr. C. Sreedhar
  • 4. Accept 2d elements and display int disp[2][3]; for(i=0; i<2; i++) { for(j=0;j<3;j++) { printf("Enter disp[%d][%d]:", i, j); scanf("%d", &disp[i][j]); } } for(i=0; i<2; i++) { for(j=0;j<3;j++) { printf("%d ", disp[i][j]); if(j==2) printf("n"); } } Dr. C. Sreedhar
  • 6. Matrix operations: addition int r,c,i,j,A[10][10], B[10][10], Sum[10][10]; scanf("%d %d",&r,&c); for(i = 0; i < r; i++) { for(j = 0; j < c; j++) scanf("%d",&A[i][j]); } for (i = 0; i < r; i++) { for (j = 0; j < c; j++) { Sum[i][j] = A[i][j] + B[i][j]; printf("%dt", Sum[i][j]); } printf("n"); } for(i = 0; i < r; i++) { for(j = 0; j < c; j++) scanf("%d",&B[i][j]); } Dr. C. Sreedhar
  • 7. int m, n, p, q, i, j, k; int a[10][10], b[10][10], res[10][10]; scanf("%d%d", & m, & n); // first matrix size scanf("%d%d", & p, & q); // second matrix size if (n != p) printf("Matrix is incompatible for multiplicationn"); else { for (i = 0; i < m; i++) { for (j = 0; j < n; j++) scanf("%d", & a[i][j]); } for (i = 0; i < p; i++) { for (j = 0; j < q; j++) scanf("%d", & b[i][j]); } Matrix Mult Dr. C. Sreedhar
  • 8. for (i = 0; i < m; i++) { for (j = 0; j < q; j++) { res[i][j] = 0; for (k = 0; k < p; k++) res[i][j] += a[i][k] * b[k][j]; } } for (i = 0; i < m; i++) { for (j = 0; j < q; j++) printf("%dt", res[i][j]); printf("n"); } } Matrix Mult Dr. C. Sreedhar
  • 9. pass two-dimensional arrays to function void Function(int c[2][2]); int main() { int c[2][2],i,j; printf("Enter 4 numbers:n"); for(i=0;i<2;++i) for(j=0;j<2;++j) { scanf("%d",&c[i][j]); } Function(c); return 0; } Enter 4 numbers: 2 3 4 5 Displaying: 2 3 4 5 void Function(int c[2][2]) { int i,j; printf("Displaying:n"); for(i=0;i<2;++i) for(j=0;j<2;++j) printf("%dn",c[i][j]); } Dr. C. Sreedhar
  • 10. Matrix Mult: UDF Input(a,m,n); Input(b,p,q); display(a,m,n); display(b,p,q); multiply(a,b,c,m,n,p,q); display(c,m,q); void input(int a[][10], int m, int n) { int i, j; printf("nEnter matr.elements:"); for (i = 0; i < m; ++i) { for (j = 0; j < n; ++j) scanf("%d", & a[i][j]); } } Dr. C. Sreedhar
  • 11. Matrix Mult: UDF Input(a,m,n); Input(b,p,q); display(a,m,n); display(b,p,q); multiply(a,b,c,m,n,p,q); display(c,m,q); void display(int a[][10], int m,int n) { int i, j; for (i = 0; i < m; i++) { for (j = 0; j < n; j++) printf("%d", a[i][j]); printf("n") } } Dr. C. Sreedhar
  • 12. Matrix Mult: UDF Input(a,m,n); Input(b,p,q); display(a,m,n); display(b,p,q); multiply(a,b,c,m,n,p,q); display(c,m,q); void multiply(int a[][10], int b[][10], int c[][10], int m, int n, int p, int q) { int i, j, k; for (i = 0; i < m; ++i) { for (j = 0; j < q; ++j) c[i][j] = 0; } for (i = 0; i < m; ++i) { for (j = 0; j < q; ++j) { for (k = 0; k < n; ++k) c[i][j] += a[i][k] * b[k][j]; } } } Dr. C. Sreedhar
  • 13. for (int i = 0; i < r; ++i) for (int j = 0; j < c; ++j) scanf("%d", &a[i][j]); for (int i = 0; i < r; ++i) for (int j = 0; j < c; ++j) transpose[j][i] = a[i][j]; for (int i = 0; i < c; ++i) for (int j = 0; j < r; ++j) { printf("%d ", transpose[i][j]); if (j == r - 1) printf("n"); } Matrix Transpose Dr. C. Sreedhar
  • 14. int matrix[3][3],sum = 0; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { if(i == j) sum += matrix[i][j]; } } for(int i=0; i<3; i++) { for(int j=0; j<3; j++) printf("%d ", matrix[i][j]); printf("n"); } printf("Sum of diagonal elements = %dn", sum); Sum of diagonal elements of matrix Dr. C. Sreedhar
  • 15. MultiDim.Array: Declaration, Initialization, Accessing  Syntax: datatype arrname[size1][size2]...[sizeN];  Declaration: int threeD[2][3][4];  Initialization:  int arr[3][2][2]={0,1,2,3,4,5,6,7,8,9,3,2};  int arr[3][3][3]= { { {10,20,30},{40,50,60},{70,80,90} }, { {11,22,33},{44,55,66},{77,88,99} }, { {12,23,34},{45,56,67},{78,89,90} } }; Dr. C. Sreedhar
  • 16. arr[3][3] = [ a00, a01, a02 ] [ b10, b11, b12 ] [ c20, c21, c22 ] Row major order = a00, a01, a02, b10, b11, b12, c20, c12, c22 Column major order = a00, b10, c20, a01, b11, c21, a02, b12, c22
  • 17. Command line arguments  There are 2 components of Command Line Argument in C:  argc:  refers to “argument count”. It is the first parameter that we use to store the number of command line arguments.  value of argc should be greater than or equal to 0.  agrv:  refers to “argument vector”. It is basically an array of character pointer to list all the command line arguments. Dr. C. Sreedhar
  • 18. #include<stdio.h> int main(int argc, char** argv) { printf("Welcome to PPSn"); int i; printf("The number of arguments are: %dn",argc); printf("The arguments are:"); for ( i = 0; i < argc; i++) { printf("%sn", argv[i]); } return 0; } Dr. C. Sreedhar
  • 19. int main( int argc, char *argv[] ) { if( argc == 2 ) { printf("The argument supplied is %sn", argv[1]); } else if( argc > 2 ) { printf("Too many arguments supplied.n"); } else { printf("One argument expected.n"); } } Dr. C. Sreedhar