//BAI 1
#include <iostream>
using namespace std;
void nhapmang(int a[][100], int n, int m)
{
for (int i = 0; i < m; i++)
{
for (int j = 0; j < n; j++)
{
cout << "Nhap a[" << i << "]" << "[" << j << "] :";
cin >> a[i][j];
}
cout << endl;
}
}
void xuatmang(int a[][100], int n, int m)
{
for (int i = 0; i < m; i++)
{
for (int j = 0; j < n; j++)
{
cout << " " << a[i][j];
}
cout << "\n\n";
}
}
int main()
{
int a[100][100], n, m, tam = 0;
cout << "Nhap m : ";
cin >> m;
cout << "Nhap n : ";
cin >> n;
nhapmang(a, m, n);
cout << "Mang ban vua nhap la :\n" << endl;
xuatmang(a, m, n);
for (int i = 0; i < m; i++)
{
int tong = 0;
for (int j = 0; j < n; j++)
{
tong = tong + a[j][i];
if (tong > tam)
tam = tong;
}
}
cout << "Tong cot lon nhat la : " << tam << endl;
return 0;
}
-------------------------------------------------------------------->
//BAI 2
#include <iostream>
using namespace std;
int main()
{
int a[50], n, tam = 100;
cout << "Nhap n : ";
cin >> n;
bool check = true;
for (int i = 0; i < n; i++)
{
cout << "Nhap a[" << i << "]:";
cin >> a[i];
if (a[i] < tam)
{
tam = a[i];
check = true;
}
else
{
check = false;
}
}
if (check == true)
cout << "Day so giam dan!";
else
cout << "Day so ko giam dan!";
cout << endl;
return 0;
}
----------------------------------------------------------------------->
//BAI 3
#include <iostream>
using namespace std;
typedef struct phanso PHANSO;
struct phanso
{
int tuso;
int mauso;
};
void nhapphanso1(PHANSO *a )
{
cout << "Nhap vao phan so thu 1! " << endl;
cout << "Nhap vao tu so : ";
cin >> a->tuso;
do{
cout << "Nhap vao mau so : ";
cin >> a->mauso;
if (a->mauso == 0)
{
cout << "Mau so phai khac 0! xin kiem tra lai! \n";
}
} while (a->mauso == 0);
}
void nhapphanso2(PHANSO *b)
{
cout << "Nhap vao phan so thu 2! " << endl;
cout << "Nhap vao tu so : ";
cin >> b->tuso;
do{
cout << "Nhap vao mau so : ";
cin >> b->mauso;
if (b->mauso == 0)
{
cout << "Mau so phai khac 0! xin kiem tra lai! \n";
}
} while (b->mauso == 0);
}
void xuatphanso(PHANSO *a, PHANSO *b)
{
cout << a->tuso << "/" << a->mauso << " x ";
cout << b->tuso << "/" << b->mauso << " = " << double(a->tuso*b->tuso) / (a->mauso * b->mauso) << endl;
cout << a->tuso << "/" << a->mauso << " : ";
cout << b->tuso << "/" << b->mauso << " = " << double(a->tuso*b->mauso) / (a->mauso * b->tuso) << endl;
}
int main()
{
PHANSO *a = new PHANSO;
PHANSO *b = new PHANSO;
nhapphanso1(a);
nhapphanso2(b);
xuatphanso(a,b);
delete a;
delete b;
return 0;
}
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.