1-Arrays (rows and columns):
#include <iostream.h>
#include <conio.h>
void main( )
{
int b[3][3];
int i,j;
cout << "Enter numbers: \n";
for (i=0; i<3; i++)
{for (j=0; j<3; j++)
cin >> b[i][j];}
for (i=0; i<3; i++)
{for (j=0; j<3; j++)
cout << b[i][j];
cout << "\n";}
getch ();
}
2-Printing a smaller number of matrix:
#include <iostream.h>
#include <conio.h>
void main( )
{
int t[3][3],m,i,j;
cout << "Enter numbers: \n";
for (i=0; i<3; i++)
{for (j=0; j<3; j++)
cin >> t[i][j];}
m = t[0][0];
for (i=0; i<3; i++)
{for (j=0; j<3; j++)
if (m > t[i][j])
m = t[i][j];}
cout << "min= " << m;
getch ();
}
If we want to print larger number of the matrix Condition becomes if (m < t[i])
3-Program to simulate a simple calculator operations are addition, subtraction,multiplication and division where the user enter the number first then the code processand then the second number
#include <iostream.h>
#include <conio.h>
void main ( )
{
float x , y , z;
char a , oper ;
do
{
cout << "\nEnter First number,Operator,Second number: ";
cin >> x >> oper >> y ;
switch (oper)
{
case '+' : z=x+y ; break;
case '-' : z=x-y ; break;
case '*' : z=x*y ; break;
case '/' : z=x/y ; break;
default : z=0;
}
cout << "The answer is: " << z;
cout << "\nDo another (y/n)?";
cin >> a ;
}
while (a != 'n');
getch ();
}
0 comments:
Post a Comment