C++ program to Find out Maximum and Minimum within and Array
C++ Program to perform Matrix operations i.e Addition and Multiplication of two Matrices.
#include<iostream.h> #include<conio.h> void main() { clrscr(); int a[10]; int max=0,min; int i; for(i=0;i<=9;i++) { cout<<"Enter the element "<<i+1<<":- "; cin>>a[i]; } for(i=0;i<=9;i++) { if(max<a[i]) max=a[i]; if(min>a[i]) min=a[i]; } cout<<"\nMaximum in Array is "<<max; cout<<"\nMinimum in Array is "<<min; getch(); }
C++ Program to perform Matrix operations i.e Addition and Multiplication of two Matrices.
#include<iostream.h> #include<conio.h> #include<stdlib.h> void add(int a[3][3],int b[3][3]) { int i,j; int c[3][3]; for(i=0;i<=2;i++) { for(j=0;j<=2;j++) { c[i][j]=a[i][j]+b[i][j]; cout<<c[i][j]<<"\t"; } cout<<"\n"; } } void mul(int a[3][3],int b[3][3]) { int k=0; int i,j; int c[3][3]; for(i=0;i<3;i++) { for(j=0;j<3;j++) { c[i][j] = 0; for(k=0;k< 3;k++) c[i][j] = c[i][j] + a[i][k] * b[k][j]; cout<<c[i][j]<<"\t"; } cout<<"\n"; } } void getMat() { for(i=0;i<=2;i++) { for(j=0;j<=2;j++) { cout<<"Enter the Elements ["<<i<<","<<j<<"] for Matrix 1:- "; cin>>a[i][j]; cout<<"Enter the Elements ["<<i<<","<<j<<"] for Matrix 2:- "; cin>>b[i][j]; } } } void main() { int a[3][3]; int b[3][3]; int i,j; int ch; cout<<"\n1.Matrix Addition."; cout<<"\n2.Matrix Multiplication."; cout<<"\n3.Exit."; cout<<"\nEnter you choice:- "; cin>>ch; getMat(); switch(ch) { case 1: cout<<"\nAddition of Matrix is :- "; add(a,b); break; case 2: cout<<"\nMulitplication of Matrix is :- "; mul(a,b); break; case 3: exit(0); break; default: cout<<"\nInvalid Option"; break; } getch(); }
No comments:
Post a Comment