gcm_and_lcm.cpp
835 B
A program to find LCM and GCD of two integers.. use code::block or Falcon++
example of programe with
//continue//
#include <iostream>
using namespace std;
int main() {
for (int i = 0; i < 10; i++) {
if (i == 4) {
continue;
}
cout << i << "\n";
}
return 0;
}
/* the output is
1
2
3
4
5
6
7
8
9
10
*/
https://t.me/PROGRAMINGLANGUAGES1
//continue//
#include <iostream>
using namespace std;
int main() {
for (int i = 0; i < 10; i++) {
if (i == 4) {
continue;
}
cout << i << "\n";
}
return 0;
}
/* the output is
1
2
3
4
5
6
7
8
9
10
*/
https://t.me/PROGRAMINGLANGUAGES1
sample code with
//break// statement
#include <iostream>
using namespace std;
int main() {
for (int i = 0; i < 10; i++) {
if (i == 4) {
break;
}
cout << i << "\n";
}
return 0;
}
/*the output is
1
2
3
*/
https://t.me/PROGRAMINGLANGUAGES1
//break// statement
#include <iostream>
using namespace std;
int main() {
for (int i = 0; i < 10; i++) {
if (i == 4) {
break;
}
cout << i << "\n";
}
return 0;
}
/*the output is
1
2
3
*/
https://t.me/PROGRAMINGLANGUAGES1
#TRY_ON_YOUR IDE
C++ code that calculate addition of matrix transpose and multiplication
#include <iostream>
using namespace std;
void multi(int arr[3][4],int arr2[4][3]);
void add(int mat[3][4],int m[3][4]);
void transpose(int arr[3][4]);
int main()
{
int a;
int matrix[3][4],matri[4][3],m2[3][4];
cout<<"command; "<<"\t enter respective numbers\n\t1)transpose\t2)matrixes multipilication with another matrixes\t3) to add matrices with another\n\t4)exit ";cin>>a;
if(a!=4)
{
for(int i=0;i<3;i++)
{
cout<<"\tenter 3x4 matrices row "<<i+1<<endl;
for(int j=0;j<4;j++)
{
cin>>matrix[i][j];
}
}
}
switch(a)
{
case 1:
transpose(matrix);
do
{
main();}
while(a==4);
break;
case 2:
for(int i=0;i<4;i++)
{
cout<<"enter 4x3 matrix's row "<<i+1<<endl;
for(int j=0;j<3;j++)
{
cin>>matri[i][j];
}
}multi(matrix,matri);
do
{
main();}
while(a==4);
break;
case 3:
for(int i=0;i<3;i++)
{
cout<<"enter second 3x4 matrix's row "<<i+1<<endl;
for(int j=0;j<4;j++)
{
cin>>m2[i][j];
}
} add(matrix,m2);
do
{
main();}
while(a==4);
}
return 0;
}
void transpose(int arr[3][4])
{
cout<<endl<<"before transposing"<<endl;
for(int i=0;i<3;i++)
{
for(int j=0;j<4;j++)
{
cout<<"\t"<<arr[i][j];
}
cout<<endl;
}
cout<<"after transposing"<<endl;
for(int i=0;i<=3;i++)
{
for(int j=0;j<3;j++)
{
cout<<"\t"<<arr[j][i];
}
cout<<endl;
}
}
void multi(int arr[3][4],int arr2[4][3])
{
cout<<"\tthe multiplication of two matrices are;\n";
int temp[3][4];
for(int i=0;i<3;i++)
{
for (int j=0;j<3;j++)
{
temp[i][j]=0;
for(int k=0;k<4;k++)
{
temp[i][j]+=arr[i][k]*arr2[k][j];
}
}
}
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
cout<<"\t"<<temp[i][j];
}
cout<<endl;
}
}
void add(int mat[3][4],int m[3][4])
{
cout<<"\n\tthe addition of two matrices are: \n";
for(int i=0;i<3;i++)
{
for(int j=0;j<4;j++)
{
cout<<"\t"<<mat[i][j]+m[i][j]<<"\t";
} cout<<"\n";
}
}
https://t.me/PROGRAMINGLANGUAGES1
https://t.me/PROGRAMINGLANGUAGES1
C++ code that calculate addition of matrix transpose and multiplication
#include <iostream>
using namespace std;
void multi(int arr[3][4],int arr2[4][3]);
void add(int mat[3][4],int m[3][4]);
void transpose(int arr[3][4]);
int main()
{
int a;
int matrix[3][4],matri[4][3],m2[3][4];
cout<<"command; "<<"\t enter respective numbers\n\t1)transpose\t2)matrixes multipilication with another matrixes\t3) to add matrices with another\n\t4)exit ";cin>>a;
if(a!=4)
{
for(int i=0;i<3;i++)
{
cout<<"\tenter 3x4 matrices row "<<i+1<<endl;
for(int j=0;j<4;j++)
{
cin>>matrix[i][j];
}
}
}
switch(a)
{
case 1:
transpose(matrix);
do
{
main();}
while(a==4);
break;
case 2:
for(int i=0;i<4;i++)
{
cout<<"enter 4x3 matrix's row "<<i+1<<endl;
for(int j=0;j<3;j++)
{
cin>>matri[i][j];
}
}multi(matrix,matri);
do
{
main();}
while(a==4);
break;
case 3:
for(int i=0;i<3;i++)
{
cout<<"enter second 3x4 matrix's row "<<i+1<<endl;
for(int j=0;j<4;j++)
{
cin>>m2[i][j];
}
} add(matrix,m2);
do
{
main();}
while(a==4);
}
return 0;
}
void transpose(int arr[3][4])
{
cout<<endl<<"before transposing"<<endl;
for(int i=0;i<3;i++)
{
for(int j=0;j<4;j++)
{
cout<<"\t"<<arr[i][j];
}
cout<<endl;
}
cout<<"after transposing"<<endl;
for(int i=0;i<=3;i++)
{
for(int j=0;j<3;j++)
{
cout<<"\t"<<arr[j][i];
}
cout<<endl;
}
}
void multi(int arr[3][4],int arr2[4][3])
{
cout<<"\tthe multiplication of two matrices are;\n";
int temp[3][4];
for(int i=0;i<3;i++)
{
for (int j=0;j<3;j++)
{
temp[i][j]=0;
for(int k=0;k<4;k++)
{
temp[i][j]+=arr[i][k]*arr2[k][j];
}
}
}
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
cout<<"\t"<<temp[i][j];
}
cout<<endl;
}
}
void add(int mat[3][4],int m[3][4])
{
cout<<"\n\tthe addition of two matrices are: \n";
for(int i=0;i<3;i++)
{
for(int j=0;j<4;j++)
{
cout<<"\t"<<mat[i][j]+m[i][j]<<"\t";
} cout<<"\n";
}
}
https://t.me/PROGRAMINGLANGUAGES1
https://t.me/PROGRAMINGLANGUAGES1
#Single_Dimensional_Array
The single-dimensional array may be defined as the type of array capable of holding the values of the same data centre in the form of a list
EXAMPLE; SEE BELOW
#include <iostream>
#include <conio.h>
using namespace std;
void main()
{
int val_array[3];
int int_val=1,counter;
cout<<"Please enter three numbers that you want to multiply"<<endl;
for(counter=0;counter<3;counter++)
{
cin>>val_array[counter];
int_val = int_val*val_array[counter];
}
cout<<"The multiplication of these three numbers is = "<<int_val;
getch();
}
#Multidimensional_Array
The multidimensional array may be defined as the array that holds the values in the way a matrix does. The two-dimensional array is used very often, and with the increase in the size of dimension, the array gets complicated.
EXAMPLE; SEE BELOW
#include <iostream>
#include <conio.h>
using namespace std;
int main()
{
int val_array[5][5];
int count_rows,count_cols,counter1,counter2;
cout<<"Please enter the size of the rows and columns that you wnant to input: ";
cin>>count_rows>>count_cols;
cout<<"PLease enter the values for matrics in row wise manner"<<endl;
for(counter1=0;counter1<count_rows;counter1++)
for(counter2=0;counter2<count_cols;counter2++)
cin>>val_array[counter1][counter2];
cout<<"The matrix will be as follows"<<endl;
for(counter1=0;counter1<count_rows;counter1++)
{
for(counter2=0;counter2<count_cols;counter2++)
cout<<val_array[counter1][counter2]<<" ";
cout<<endl;
}
getch();
return 0;
}
https://t.me/PROGRAMINGLANGUAGES1
The single-dimensional array may be defined as the type of array capable of holding the values of the same data centre in the form of a list
EXAMPLE; SEE BELOW
#include <iostream>
#include <conio.h>
using namespace std;
void main()
{
int val_array[3];
int int_val=1,counter;
cout<<"Please enter three numbers that you want to multiply"<<endl;
for(counter=0;counter<3;counter++)
{
cin>>val_array[counter];
int_val = int_val*val_array[counter];
}
cout<<"The multiplication of these three numbers is = "<<int_val;
getch();
}
#Multidimensional_Array
The multidimensional array may be defined as the array that holds the values in the way a matrix does. The two-dimensional array is used very often, and with the increase in the size of dimension, the array gets complicated.
EXAMPLE; SEE BELOW
#include <iostream>
#include <conio.h>
using namespace std;
int main()
{
int val_array[5][5];
int count_rows,count_cols,counter1,counter2;
cout<<"Please enter the size of the rows and columns that you wnant to input: ";
cin>>count_rows>>count_cols;
cout<<"PLease enter the values for matrics in row wise manner"<<endl;
for(counter1=0;counter1<count_rows;counter1++)
for(counter2=0;counter2<count_cols;counter2++)
cin>>val_array[counter1][counter2];
cout<<"The matrix will be as follows"<<endl;
for(counter1=0;counter1<count_rows;counter1++)
{
for(counter2=0;counter2<count_cols;counter2++)
cout<<val_array[counter1][counter2]<<" ";
cout<<endl;
}
getch();
return 0;
}
https://t.me/PROGRAMINGLANGUAGES1
👍1🎉1
👍6❤1👎1