SlideShare a Scribd company logo
1 of 16
Download to read offline
TUTORIAL 5 SJEM2231: STRUCTURED PROGRAMMING (C++)
QUESTION 1
Write a C++ program to find the mean (average) of N numbers stored in
an array
#include <iostream>
using namespace std;
int main()
{
int n, i;
float number[100], sum=0, average;
cout << "Enter the total numbers of data: ";
cin >> n;
while (n >100 || n<=0)
{
cout << "Error! the number should in range of (1 to 100).n”;
cout << “Plase enter the number again: “;
cin >> n;
}
for(i=0; i<n; i++)
{
cout << “Enter a number: “;
cin >> number[i];
sum= sum + number[i];
}
average=sum / n;
cout << “nThe average is: “ << average << endl;
return 0;
}
//Output:
Enter the total numbers of data: 101
Error! the number should in range of (1 to 100).
Plase enter the number again: -4
Error! the number should in range of (1 to 100).
Plase enter the number again: 5
Enter a number: 4
Enter a number: 7
Enter a number: 2
Enter a number: 9
Enter a number: 15
The average is: 7.4
QUESTION 2
Write a C++ program to find the smallest number in one-dimensional
array of order n
#include<iostream>
using namespace std;
int main()
{
int n,i, farhan[20], min;
TUTORIAL 5 SJEM2231: STRUCTURED PROGRAMMING (C++)
cout << "Enter the total number of elements for 1-D array : ";
cin >> n;
for(i=0;i<n;i++)
{
cout <<"Enter the element of farhan: ";
cin >> farhan[i];
}
min = farhan[0];
for(i=0;i<n;i++)
{
if(min > farhan[i])
min= farhan[i];
}
cout <<"nThe smallest element is: " << min << endl;
return 0;
}
//Output:
Enter the total number of elements for 1-D array : 7
Enter the element of farhan: 3
Enter the element of farhan: 6
Enter the element of farhan: 10
Enter the element of farhan: 13
Enter the element of farhan: 1
Enter the element of farhan: 53
Enter the element of farhan: 6
The smallest element is: 1
QUESTION 3
Write a C++ program to add the given two matrices.
#include <iostream>
using namespace std;
int main()
{
int m,n,c,d, first[10][10], second[10][10], sum[10][10];
cout << "Enter the number of rows and columns of matrix" << endl;
cin >> m>> n;
cout << "Enter the elements of first matrix n";
for( c=0; c<m ; c++)
for(d=0; d<n ; d++)
cin >> first [c][d];
cout << "Enter the elements of second matrix n";
for(c=0; c<m; c++)
for(d=0; d<n; d++)
cin >> second[c][d];
TUTORIAL 5 SJEM2231: STRUCTURED PROGRAMMING (C++)
for (c=0;c<m;c++)
for(d=0;d<n;d++)
sum[c][d]= first[c][d] + second[c][d];
cout << "The summation of entered matrixes :- n";
for(c=0; c<m; c++)
{
for(d=0; d<n; d++)
cout << sum[c][d] << "t";
cout << endl;
}
return 0;
}
//Output :
Enter the number of rows and columns of matrix
4 4
Enter the elements of first matrix
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
Enter the elements of second matrix
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
The summation of entered matrixes :-
2 4 6 8
10 12 14 16
18 20 22 24
26 28 30 32
QUESTION 4
Write a C++ program to find the transpose of a given matrix.
// Using for loop:
#include <iostream>
using namespace std;
int main()
{
int m,n,c,d, matrix[10][10];
do
{
cout << "Enter the no. of rows & columns of matrix(MAX 10x10):" << endl;
cin >> m >> n ;
}
while (m<1 || n<1 || m>10 || n>10);
cout << "Enter the elements of matrix n";
for( c=0; c<m ; c++)
TUTORIAL 5 SJEM2231: STRUCTURED PROGRAMMING (C++)
for(d=0; d<n ; d++)
cin >> matrix [c][d];
cout << "The transpose of the entered matrixes :- n";
for(c=0; c<n ; c++)
{
for(d=0; d < m; d++)
cout << matrix[d][c] << "t";
cout << endl;
}
return 0;
}
// Output:
Output 1:
Enter the number of rows and columns of matrix
4 4
Enter the elements of matrix
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
The transpose of the entered matrixes :-
1 5 9 13
2 6 10 14
3 7 11 15
4 8 12 16
Output 2:
Enter the number of rows and columns of matrix
4 7
Enter the elements of matrix
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
The transpose of the entered matrixes :-
1 8 15 22
2 9 16 23
3 10 17 24
4 11 18 25
5 12 19 26
6 13 20 27
7 14 21 28
QUESTION 5
Write a C++ program for multiplication of given two matrices
2X2 DIMENSION ONLY
#include <iostream>
using namespace std;
int main()
{
int m,n,c,d, first[2][2], second[2][2], mult[2][2];
cout << "Enter the number of rows and columns of matrix" << endl;
TUTORIAL 5 SJEM2231: STRUCTURED PROGRAMMING (C++)
cin >> m>> n;
cout << "Enter the elements of first matrix n";
for( c=0; c<m ; c++)
for(d=0; d<n ; d++)
cin >> first [c][d];
cout << "Enter the elements of second matrix n";
for(c=0; c<m; c++)
for(d=0; d<n; d++)
cin >> second[c][d];
for (c=0;c<m;c++)
for(d=0;d<n;d++)
mult[c][d]= first[c][0] * second[0][d] + first[c][1] * second[1][d];
cout << "Multiplication of entered matrixes :- n";
for(c=0; c<m; c++)
{
for(d=0; d<n; d++)
cout << mult[c][d] << "t";
cout << endl;
}
return 0;
}
//Output :
Enter the number of rows and columns of matrix
2 2
Enter the elements of first matrix
1 2
3 4
Enter the elements of second matrix
1 2
3 4
Multiplication of entered matrixes :-
7 10
15 22
FOR OTHER DIMENSIONS UP TO 10X10 (FIRST ALTERNATIVE)
#include <iostream>
using namespace std;
int main()
{
int m,n,k,l,c,d, first[10][10], second[10][10], mult[10][10];
cout << "Enter the number of rows and columns of first matrix" << endl;
cin >> m>> n;
// m denotes number of rows in first matrix
// n denotes number of columns in first matrix
cout << "Enter the elements of first matrix n";
for( c=0; c<m ; c++)
TUTORIAL 5 SJEM2231: STRUCTURED PROGRAMMING (C++)
for(d=0; d<n ; d++)
cin >> first [c][d];
cout << "Enter the number of rows and columns of second matrix" << endl;
cin >> k >> l;
// k denotes number of rows in second matrix
// l denotes number of columns in second matrix
cout << "Enter the elements of second matrix n";
for(c=0; c<k; c++)
for(d=0; d<l; d++)
cin >> second[c][d];
if(n==k)
{
for(c=0;c<m;c++)
{
for(d=0;d<l;d++)
{
mult[c][d]=0;
for(int x=0; x < k ; x++)
{
mult[c][d]= mult[c][d]+ first[c][x]* second[x][d];
}
}
}
cout<<"nThe multiplication of first matrix and second matrix is : " << endl;
for(c=0; c<m; c++)
{
for(d=0 ; d<l;d++)
{
cout<< mult[c][d] << "t";
}
cout<< endl;
}
}
else
{
cout<<"nnMultiplication is not possible" ;
}
return 0;
}
//Output :
Output 1:
Enter the number of rows and columns of first matrix
4 4
Enter the elements of first matrix
1 2 3 4
5 6 7 8
TUTORIAL 5 SJEM2231: STRUCTURED PROGRAMMING (C++)
9 10 11 12
13 14 15 16
Enter the number of rows and columns of second matrix
4 4
Enter the elements of second matrix
16 15 14 13
12 11 10 9
8 7 6 5
4 3 2 1
The multiplication of first matrix and second matrix is :
80 70 60 50
240 214 188 162
400 358 316 274
560 502 444 386
Output 2:
Enter the number of rows and columns of first matrix
2 5
Enter the elements of first matrix
1 2 3 4 5
6 7 8 9 10
Enter the number of rows and columns of second matrix
5 3
Enter the elements of second matrix
1 2 3
4 5 6
7 8 9
10 11 12
13 14 15
The multiplication of first matrix and second matrix is :
135 150 165
310 350 390
FOR OTHER DIMENSIONS UP TO 10X10 (SECOND ALTERNATIVE)
#include <iostream>
using namespace std;
int main ()
{
int m,n,a,b,i,j,k,sum = 0,A[10][10],B[10][10];
cout << "THE MULTIPLICATION OF TWO MATRICES WITH
DIFFERENT DIMENSIONS" << endl;
cout << "COLUMN OF 1ST = ROW OF 2ND" << endl;
do
{
cout << "nPlease enter the dimension of the first Matrix(MAX 10x10):" <<
endl;
cin >> m >> n ;
cout << "Please enter the dimension of the second Matrix(MAX 10x10):"
<< endl;
TUTORIAL 5 SJEM2231: STRUCTURED PROGRAMMING (C++)
cin >> a >> b ;
} while (m<1 || n<1 || m>10 || n>10 || a<1 || b<1 || a>10 || b>10 || n!=a);
cout << "Please enter the first matrix:" << endl;
for (i=0;i<m;i++)
for (j=0;j<n;j++)
cin >> A[i][j] ;
cout << "Please enter the second matrix:" << endl;
for (i=0;i<a;i++)
for (j=0; j<b;j++)
cin >> B[i][j] ;
cout << "nThe multiplication of two matrices is:" << endl;
for (i=0;i<m;i++)
{
for (j=0;j<b;j++)
{
for (k=0; k<n; k++)
sum = sum + A[i][k] * B[k][j];
cout << sum << "t" ;
}
cout << endl;
}
return 0;
}
//Output:
THE MULTIPLICATION OF TWO MATRICES WITH DIFFERENT DIMENSIONS
COLUMN OF 1ST = ROW OF 2ND
Please enter the dimension of the first Matrix(MAX 10x10):
2 9
Please enter the dimension of the second Matrix(MAX 10x10):
2 1
Please enter the dimension of the first Matrix(MAX 10x10):
3 2
Please enter the dimension of the second Matrix(MAX 10x10):
2 4
Please enter the first matrix:
1 2
3 4
5 6
Please enter the second matrix:
1 2 3 4
5 6 7 8
The multiplication of two matrices is:
11 25 42 62
85 115 152 196
231 277 334 402

More Related Content

What's hot

Ejercicios resueltos de programacion
Ejercicios resueltos de programacionEjercicios resueltos de programacion
Ejercicios resueltos de programacionJaime amambal
 
Metodo de la burbuja en algoritmo
Metodo de la burbuja en algoritmo Metodo de la burbuja en algoritmo
Metodo de la burbuja en algoritmo ikky2345
 
Introducción A Las Estructuras De Seleccion En C
Introducción A Las Estructuras De Seleccion En CIntroducción A Las Estructuras De Seleccion En C
Introducción A Las Estructuras De Seleccion En Cpainni
 
02 Ejercicios Resueltos diagramas de flujo
02 Ejercicios Resueltos diagramas de flujo02 Ejercicios Resueltos diagramas de flujo
02 Ejercicios Resueltos diagramas de flujoTete Alar
 
Palabras Reservadas en C++
Palabras Reservadas en C++Palabras Reservadas en C++
Palabras Reservadas en C++ncrmax
 
Serie Fibonacci en C
Serie Fibonacci en CSerie Fibonacci en C
Serie Fibonacci en CAbraham
 
Unidad 4 est. dat. recursividad
Unidad 4  est. dat. recursividadUnidad 4  est. dat. recursividad
Unidad 4 est. dat. recursividadrehoscript
 
Tipos de metodos numericos
Tipos de metodos numericosTipos de metodos numericos
Tipos de metodos numericosTensor
 

What's hot (12)

Ejercicios resueltos de programacion
Ejercicios resueltos de programacionEjercicios resueltos de programacion
Ejercicios resueltos de programacion
 
Ingenieria economica
Ingenieria  economicaIngenieria  economica
Ingenieria economica
 
Metodo de la burbuja en algoritmo
Metodo de la burbuja en algoritmo Metodo de la burbuja en algoritmo
Metodo de la burbuja en algoritmo
 
Introducción A Las Estructuras De Seleccion En C
Introducción A Las Estructuras De Seleccion En CIntroducción A Las Estructuras De Seleccion En C
Introducción A Las Estructuras De Seleccion En C
 
Gauss jordan en C
Gauss jordan en CGauss jordan en C
Gauss jordan en C
 
Algoritmos
AlgoritmosAlgoritmos
Algoritmos
 
02 Ejercicios Resueltos diagramas de flujo
02 Ejercicios Resueltos diagramas de flujo02 Ejercicios Resueltos diagramas de flujo
02 Ejercicios Resueltos diagramas de flujo
 
Palabras Reservadas en C++
Palabras Reservadas en C++Palabras Reservadas en C++
Palabras Reservadas en C++
 
Serie Fibonacci en C
Serie Fibonacci en CSerie Fibonacci en C
Serie Fibonacci en C
 
Unidad 4 est. dat. recursividad
Unidad 4  est. dat. recursividadUnidad 4  est. dat. recursividad
Unidad 4 est. dat. recursividad
 
Conteo
ConteoConteo
Conteo
 
Tipos de metodos numericos
Tipos de metodos numericosTipos de metodos numericos
Tipos de metodos numericos
 

Similar to C++ TUTORIAL 5

2 d array(part 2) || 2D ARRAY FUNCTION WRITING || GET 100% MARKS IN CBSE CS
2 d array(part 2) || 2D ARRAY FUNCTION WRITING || GET 100% MARKS IN CBSE CS2 d array(part 2) || 2D ARRAY FUNCTION WRITING || GET 100% MARKS IN CBSE CS
2 d array(part 2) || 2D ARRAY FUNCTION WRITING || GET 100% MARKS IN CBSE CSAAKASH KUMAR
 
Cse 121 presentation on matrix [autosaved]
Cse 121 presentation on matrix [autosaved]Cse 121 presentation on matrix [autosaved]
Cse 121 presentation on matrix [autosaved]Kanis Fatema Shanta
 
12th CBSE Practical File
12th CBSE Practical File12th CBSE Practical File
12th CBSE Practical FileAshwin Francis
 
Notes for C++ Programming / Object Oriented C++ Programming for MCA, BCA and ...
Notes for C++ Programming / Object Oriented C++ Programming for MCA, BCA and ...Notes for C++ Programming / Object Oriented C++ Programming for MCA, BCA and ...
Notes for C++ Programming / Object Oriented C++ Programming for MCA, BCA and ...ssuserd6b1fd
 
Introduction to cpp (c++)
Introduction to cpp (c++)Introduction to cpp (c++)
Introduction to cpp (c++)Arun Umrao
 
Oops lab manual2
Oops lab manual2Oops lab manual2
Oops lab manual2Mouna Guru
 
2014 computer science_question_paper
2014 computer science_question_paper2014 computer science_question_paper
2014 computer science_question_papervandna123
 

Similar to C++ TUTORIAL 5 (20)

C++ ARRAY WITH EXAMPLES
C++ ARRAY WITH EXAMPLESC++ ARRAY WITH EXAMPLES
C++ ARRAY WITH EXAMPLES
 
2 d array(part 2) || 2D ARRAY FUNCTION WRITING || GET 100% MARKS IN CBSE CS
2 d array(part 2) || 2D ARRAY FUNCTION WRITING || GET 100% MARKS IN CBSE CS2 d array(part 2) || 2D ARRAY FUNCTION WRITING || GET 100% MARKS IN CBSE CS
2 d array(part 2) || 2D ARRAY FUNCTION WRITING || GET 100% MARKS IN CBSE CS
 
Cse 121 presentation on matrix [autosaved]
Cse 121 presentation on matrix [autosaved]Cse 121 presentation on matrix [autosaved]
Cse 121 presentation on matrix [autosaved]
 
C++ practical
C++ practicalC++ practical
C++ practical
 
Computer Programming- Lecture 9
Computer Programming- Lecture 9Computer Programming- Lecture 9
Computer Programming- Lecture 9
 
.net progrmming part2
.net progrmming part2.net progrmming part2
.net progrmming part2
 
2D array
2D array2D array
2D array
 
12th CBSE Practical File
12th CBSE Practical File12th CBSE Practical File
12th CBSE Practical File
 
Cpp programs
Cpp programsCpp programs
Cpp programs
 
C++ file
C++ fileC++ file
C++ file
 
C++ file
C++ fileC++ file
C++ file
 
Arrays
ArraysArrays
Arrays
 
C++ TUTORIAL 8
C++ TUTORIAL 8C++ TUTORIAL 8
C++ TUTORIAL 8
 
Pointer
PointerPointer
Pointer
 
Notes for C++ Programming / Object Oriented C++ Programming for MCA, BCA and ...
Notes for C++ Programming / Object Oriented C++ Programming for MCA, BCA and ...Notes for C++ Programming / Object Oriented C++ Programming for MCA, BCA and ...
Notes for C++ Programming / Object Oriented C++ Programming for MCA, BCA and ...
 
Introduction to cpp (c++)
Introduction to cpp (c++)Introduction to cpp (c++)
Introduction to cpp (c++)
 
Oops lab manual2
Oops lab manual2Oops lab manual2
Oops lab manual2
 
C++ file
C++ fileC++ file
C++ file
 
Doc 20180130-wa0006
Doc 20180130-wa0006Doc 20180130-wa0006
Doc 20180130-wa0006
 
2014 computer science_question_paper
2014 computer science_question_paper2014 computer science_question_paper
2014 computer science_question_paper
 

More from Farhan Ab Rahman (11)

C++ TUTORIAL 10
C++ TUTORIAL 10C++ TUTORIAL 10
C++ TUTORIAL 10
 
C++ TUTORIAL 9
C++ TUTORIAL 9C++ TUTORIAL 9
C++ TUTORIAL 9
 
C++ TUTORIAL 7
C++ TUTORIAL 7C++ TUTORIAL 7
C++ TUTORIAL 7
 
C++ TUTORIAL 6
C++ TUTORIAL 6C++ TUTORIAL 6
C++ TUTORIAL 6
 
C++ TUTORIAL 4
C++ TUTORIAL 4C++ TUTORIAL 4
C++ TUTORIAL 4
 
C++ TUTORIAL 3
C++ TUTORIAL 3C++ TUTORIAL 3
C++ TUTORIAL 3
 
C++ TUTORIAL 2
C++ TUTORIAL 2C++ TUTORIAL 2
C++ TUTORIAL 2
 
C++ TUTORIAL 1
C++ TUTORIAL 1C++ TUTORIAL 1
C++ TUTORIAL 1
 
VIBRATIONS AND WAVES TUTORIAL#2
VIBRATIONS AND WAVES TUTORIAL#2VIBRATIONS AND WAVES TUTORIAL#2
VIBRATIONS AND WAVES TUTORIAL#2
 
Notis Surau
Notis SurauNotis Surau
Notis Surau
 
Kitab Bakurah.amani
Kitab Bakurah.amaniKitab Bakurah.amani
Kitab Bakurah.amani
 

Recently uploaded

Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementmkooblal
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxAvyJaneVismanos
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerunnathinaik
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...jaredbarbolino94
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceSamikshaHamane
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxJiesonDelaCerna
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfUjwalaBharambe
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,Virag Sontakke
 

Recently uploaded (20)

Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of management
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptx
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developer
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in Pharmacovigilance
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptx
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
 

C++ TUTORIAL 5

  • 1. TUTORIAL 5 SJEM2231: STRUCTURED PROGRAMMING (C++) QUESTION 1 Write a C++ program to find the mean (average) of N numbers stored in an array #include <iostream> using namespace std; int main() { int n, i; float number[100], sum=0, average; cout << "Enter the total numbers of data: "; cin >> n; while (n >100 || n<=0) { cout << "Error! the number should in range of (1 to 100).n”; cout << “Plase enter the number again: “; cin >> n; } for(i=0; i<n; i++) { cout << “Enter a number: “; cin >> number[i]; sum= sum + number[i]; } average=sum / n;
  • 2. cout << “nThe average is: “ << average << endl; return 0; } //Output: Enter the total numbers of data: 101 Error! the number should in range of (1 to 100). Plase enter the number again: -4 Error! the number should in range of (1 to 100). Plase enter the number again: 5 Enter a number: 4 Enter a number: 7 Enter a number: 2 Enter a number: 9 Enter a number: 15 The average is: 7.4 QUESTION 2 Write a C++ program to find the smallest number in one-dimensional array of order n #include<iostream> using namespace std; int main() { int n,i, farhan[20], min;
  • 3. TUTORIAL 5 SJEM2231: STRUCTURED PROGRAMMING (C++) cout << "Enter the total number of elements for 1-D array : "; cin >> n; for(i=0;i<n;i++) { cout <<"Enter the element of farhan: "; cin >> farhan[i]; } min = farhan[0]; for(i=0;i<n;i++) { if(min > farhan[i]) min= farhan[i]; } cout <<"nThe smallest element is: " << min << endl; return 0; } //Output: Enter the total number of elements for 1-D array : 7 Enter the element of farhan: 3 Enter the element of farhan: 6 Enter the element of farhan: 10 Enter the element of farhan: 13
  • 4. Enter the element of farhan: 1 Enter the element of farhan: 53 Enter the element of farhan: 6 The smallest element is: 1 QUESTION 3 Write a C++ program to add the given two matrices. #include <iostream> using namespace std; int main() { int m,n,c,d, first[10][10], second[10][10], sum[10][10]; cout << "Enter the number of rows and columns of matrix" << endl; cin >> m>> n; cout << "Enter the elements of first matrix n"; for( c=0; c<m ; c++) for(d=0; d<n ; d++) cin >> first [c][d]; cout << "Enter the elements of second matrix n"; for(c=0; c<m; c++) for(d=0; d<n; d++) cin >> second[c][d];
  • 5. TUTORIAL 5 SJEM2231: STRUCTURED PROGRAMMING (C++) for (c=0;c<m;c++) for(d=0;d<n;d++) sum[c][d]= first[c][d] + second[c][d]; cout << "The summation of entered matrixes :- n"; for(c=0; c<m; c++) { for(d=0; d<n; d++) cout << sum[c][d] << "t"; cout << endl; } return 0; } //Output : Enter the number of rows and columns of matrix 4 4 Enter the elements of first matrix 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 Enter the elements of second matrix 1 2 3 4
  • 6. 5 6 7 8 9 10 11 12 13 14 15 16 The summation of entered matrixes :- 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 QUESTION 4 Write a C++ program to find the transpose of a given matrix. // Using for loop: #include <iostream> using namespace std; int main() { int m,n,c,d, matrix[10][10]; do { cout << "Enter the no. of rows & columns of matrix(MAX 10x10):" << endl; cin >> m >> n ; } while (m<1 || n<1 || m>10 || n>10); cout << "Enter the elements of matrix n"; for( c=0; c<m ; c++)
  • 7. TUTORIAL 5 SJEM2231: STRUCTURED PROGRAMMING (C++) for(d=0; d<n ; d++) cin >> matrix [c][d]; cout << "The transpose of the entered matrixes :- n"; for(c=0; c<n ; c++) { for(d=0; d < m; d++) cout << matrix[d][c] << "t"; cout << endl; } return 0; } // Output: Output 1: Enter the number of rows and columns of matrix 4 4 Enter the elements of matrix 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 The transpose of the entered matrixes :- 1 5 9 13 2 6 10 14 3 7 11 15 4 8 12 16
  • 8. Output 2: Enter the number of rows and columns of matrix 4 7 Enter the elements of matrix 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 The transpose of the entered matrixes :- 1 8 15 22 2 9 16 23 3 10 17 24 4 11 18 25 5 12 19 26 6 13 20 27 7 14 21 28 QUESTION 5 Write a C++ program for multiplication of given two matrices 2X2 DIMENSION ONLY #include <iostream> using namespace std; int main() { int m,n,c,d, first[2][2], second[2][2], mult[2][2]; cout << "Enter the number of rows and columns of matrix" << endl;
  • 9. TUTORIAL 5 SJEM2231: STRUCTURED PROGRAMMING (C++) cin >> m>> n; cout << "Enter the elements of first matrix n"; for( c=0; c<m ; c++) for(d=0; d<n ; d++) cin >> first [c][d]; cout << "Enter the elements of second matrix n"; for(c=0; c<m; c++) for(d=0; d<n; d++) cin >> second[c][d]; for (c=0;c<m;c++) for(d=0;d<n;d++) mult[c][d]= first[c][0] * second[0][d] + first[c][1] * second[1][d]; cout << "Multiplication of entered matrixes :- n"; for(c=0; c<m; c++) { for(d=0; d<n; d++) cout << mult[c][d] << "t"; cout << endl; } return 0; }
  • 10. //Output : Enter the number of rows and columns of matrix 2 2 Enter the elements of first matrix 1 2 3 4 Enter the elements of second matrix 1 2 3 4 Multiplication of entered matrixes :- 7 10 15 22 FOR OTHER DIMENSIONS UP TO 10X10 (FIRST ALTERNATIVE) #include <iostream> using namespace std; int main() { int m,n,k,l,c,d, first[10][10], second[10][10], mult[10][10]; cout << "Enter the number of rows and columns of first matrix" << endl; cin >> m>> n; // m denotes number of rows in first matrix // n denotes number of columns in first matrix cout << "Enter the elements of first matrix n"; for( c=0; c<m ; c++)
  • 11. TUTORIAL 5 SJEM2231: STRUCTURED PROGRAMMING (C++) for(d=0; d<n ; d++) cin >> first [c][d]; cout << "Enter the number of rows and columns of second matrix" << endl; cin >> k >> l; // k denotes number of rows in second matrix // l denotes number of columns in second matrix cout << "Enter the elements of second matrix n"; for(c=0; c<k; c++) for(d=0; d<l; d++) cin >> second[c][d]; if(n==k) { for(c=0;c<m;c++) { for(d=0;d<l;d++) { mult[c][d]=0; for(int x=0; x < k ; x++) { mult[c][d]= mult[c][d]+ first[c][x]* second[x][d]; } } }
  • 12. cout<<"nThe multiplication of first matrix and second matrix is : " << endl; for(c=0; c<m; c++) { for(d=0 ; d<l;d++) { cout<< mult[c][d] << "t"; } cout<< endl; } } else { cout<<"nnMultiplication is not possible" ; } return 0; } //Output : Output 1: Enter the number of rows and columns of first matrix 4 4 Enter the elements of first matrix 1 2 3 4 5 6 7 8
  • 13. TUTORIAL 5 SJEM2231: STRUCTURED PROGRAMMING (C++) 9 10 11 12 13 14 15 16 Enter the number of rows and columns of second matrix 4 4 Enter the elements of second matrix 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 The multiplication of first matrix and second matrix is : 80 70 60 50 240 214 188 162 400 358 316 274 560 502 444 386 Output 2: Enter the number of rows and columns of first matrix 2 5 Enter the elements of first matrix 1 2 3 4 5 6 7 8 9 10 Enter the number of rows and columns of second matrix 5 3 Enter the elements of second matrix 1 2 3
  • 14. 4 5 6 7 8 9 10 11 12 13 14 15 The multiplication of first matrix and second matrix is : 135 150 165 310 350 390 FOR OTHER DIMENSIONS UP TO 10X10 (SECOND ALTERNATIVE) #include <iostream> using namespace std; int main () { int m,n,a,b,i,j,k,sum = 0,A[10][10],B[10][10]; cout << "THE MULTIPLICATION OF TWO MATRICES WITH DIFFERENT DIMENSIONS" << endl; cout << "COLUMN OF 1ST = ROW OF 2ND" << endl; do { cout << "nPlease enter the dimension of the first Matrix(MAX 10x10):" << endl; cin >> m >> n ; cout << "Please enter the dimension of the second Matrix(MAX 10x10):" << endl;
  • 15. TUTORIAL 5 SJEM2231: STRUCTURED PROGRAMMING (C++) cin >> a >> b ; } while (m<1 || n<1 || m>10 || n>10 || a<1 || b<1 || a>10 || b>10 || n!=a); cout << "Please enter the first matrix:" << endl; for (i=0;i<m;i++) for (j=0;j<n;j++) cin >> A[i][j] ; cout << "Please enter the second matrix:" << endl; for (i=0;i<a;i++) for (j=0; j<b;j++) cin >> B[i][j] ; cout << "nThe multiplication of two matrices is:" << endl; for (i=0;i<m;i++) { for (j=0;j<b;j++) { for (k=0; k<n; k++) sum = sum + A[i][k] * B[k][j]; cout << sum << "t" ; } cout << endl; } return 0; }
  • 16. //Output: THE MULTIPLICATION OF TWO MATRICES WITH DIFFERENT DIMENSIONS COLUMN OF 1ST = ROW OF 2ND Please enter the dimension of the first Matrix(MAX 10x10): 2 9 Please enter the dimension of the second Matrix(MAX 10x10): 2 1 Please enter the dimension of the first Matrix(MAX 10x10): 3 2 Please enter the dimension of the second Matrix(MAX 10x10): 2 4 Please enter the first matrix: 1 2 3 4 5 6 Please enter the second matrix: 1 2 3 4 5 6 7 8 The multiplication of two matrices is: 11 25 42 62 85 115 152 196 231 277 334 402