---------------------------------------------------------------------------------------------
Câu 1 : viết bằng C
#include
#include
int GT (int a)
{
if (a< 2)
{
return 1;
}
else
return a*GT (a-1);
}
int main ()
{
int k,m;
do
{
printf("\nNhap m = ");
scanf("%d",&m);
if (m < 1 || m > 10)
{
printf("\nGia tri m khong hop le. Xin kiem tra lai !");
}
} while (m < 1 || m > 10);
do
{
printf("\nNhap gia tri cua k = ");
scanf ("%d",&k);
if (k < 1 || k> m)
{
printf("\nGia tri k khong hop le. Xin kiem tra lai !");
}
} while (k < 1 || k >m);
printf("\nKq cua phep toan %dC%d = %d",m,k,GT(m)/(GT (k)*GT (m-k)));
getch ();
return 0;
}
----------------------------------------------
Câu 1 : Viết bằng C++
#include <iostream>
using namespace std;
int GT (int a)
{
if (a< 2)
{
return 1;
}
else
return a*GT (a-1);
}
int main ()
{
int k,m;
do
{
cout<<"\nNhap m = ";
cin>>m;
if (m < 1 || m > 10)
{
cout<<"\nGia tri m khong hop le. Xin kiem tra lai !";
}
} while (m < 1 || m > 10);
do
{
cout<<"\nNhap gia tri cua k = ";
cin>>k;
if (k < 1 || k> m)
{
cout<<"\nGia tri k khong hop le. Xin kiem tra lai !";
}
} while (k < 1 || k >m);
cout<<"\nKq cua phep toan "<<m<<"C"<<k<<" = "<<GT(m)/(GT (k)*GT (m-k));
system ("pause");
return 0;
}
-----------------------------------------------
Câu 2 : viết bằng C
#include <stdio.h>
#include <conio.h>
#define MAX 100
int TinhTong (int a[][100],int dong, int cot)
{
int Tong = 0;
for (int i =0;i < dong;i++)
{
for (int j = 0;j < cot; j++)
{
if (a[i][j] > 0)
Tong+= a[i][j];
}
}
return Tong;
}
main ()
{
//Nhap mang
int a[MAX][MAX];
int dong,cot;
do{
printf ("\nNhap so dong = ");
scanf ("%d",&dong);
if (dong < 0 || dong > MAX)
printf ("\nSo dong khong hop le. Xin kiem tra lai !");
}while (dong < 0 || dong > MAX);
do{
printf ("\nNhap so cot = ");
scanf ("%d",&cot);
if (cot < 0 || cot > MAX)
printf ("\nSo cot khong hop le. Xin kiem tra lai !");
}while (cot < 0 || cot > MAX);
for (int i =0;i < dong;i++)
{
for (int j = 0;j < cot; j++)
{
printf ("\nNhap a[%d][%d] = ",i,j);
scanf ("%d",&a[i][j]);
}
}
//Xuat mang
for (int i =0;i < dong;i++)
{
for (int j = 0;j < cot; j++)
{
printf ("%4d",a[i][j]);
}
printf ("\n");
}
printf ("\nTong cac phan tu duong trong mang = %d",TinhTong (a,dong,cot));
getch ();
return 0;
}
------------------------------------------------
Câu 2 : viết bằng C++
#include <iostream>
using namespace std;
#define MAX 100
int TinhTong (int a[][100],int dong, int cot)
{
int Tong = 0;
for (int i =0;i < dong;i++)
{
for (int j = 0;j < cot; j++)
{
if (a[i][j] > 0)
Tong+= a[i][j];
}
}
return Tong;
}
main ()
{
//Nhap mang
int a[MAX][MAX];
int dong,cot;
do{
cout<<"\nNhap so dong = ";
cin>>dong;
if (dong < 0 || dong > MAX)
cout<<"\nSo dong khong hop le. Xin kiem tra lai !";
}while (dong < 0 || dong > MAX);
do{
cout<<"\nNhap so cot = ";
cin>>cot;
if (cot < 0 || cot > MAX)
cout<<"\nSo cot khong hop le. Xin kiem tra lai !";
}while (cot < 0 || cot > MAX);
for (int i =0;i < dong;i++)
{
for (int j = 0;j < cot; j++)
{
cout<<"\nNhap a["<<i<<"]["<<j<<"] = ";
cin>>a[i][j];
}
}
//Xuat mang
for (int i =0;i < dong;i++)
{
for (int j = 0;j < cot; j++)
{
cout<<a[i][j]<< " ";
}
cout<<"\n";
}
cout<<"\nTong cac phan tu duong trong mang = "<<TinhTong (a,dong,cot);
system ("pause");
return 0;
}
------------------------------------------------
Câu 3 : viết bằng C
#include <stdio.h>
#include <conio.h>
#define MAX 1000
#include <string.h>
typedef struct NhanVien
{
char MaNV[40];
char TenNV[40];
char GT[4];
int NS;
char DV [40];
}NV;
void Nhap (NV &a)
{
printf ("\nNhap Ma nv : "); fflush (stdin);gets (a.MaNV);
printf ("\nNhap Ho Ten nv : ");fflush (stdin);gets (a.TenNV);
printf ("\nNhap gioi tinh nv : ");fflush (stdin);gets (a.GT);
printf ("\nNhap nam sinh cua nhan vien : ");scanf ("%d",&a.NS);
printf ("\nNhap don vi cu nhan vien : ");fflush (stdin);gets (a.DV);
printf ("\n----------------");
}
void Xuat (NV a)
{
printf ("\nMa nv : "); fflush (stdin);puts (a.MaNV);
printf ("\nHo Ten nv : ");fflush (stdin);puts (a.TenNV);
printf ("\\Gioi tinh nv : ");fflush (stdin);puts (a.GT);
printf ("\nNam sinh cua nhan vien : ");printf ("%d",a.NS);
printf ("\nDon vi cu nhan vien : ");fflush (stdin);puts (a.DV);
printf("\n----------------");
}
void Nhap2 (NV a[], int &n)
{
for (int i = 0; i <n; i++)
{
printf("\nThong tin NV thu %d",i+1);
Nhap(a[i]);
}
}
void Xuat2 (NV a[], int n)
{
for (int i = 0; i <n; i++)
{
Xuat(a[i]);
}
}
void TimKiem (NV a[], int n)
{
for (int i =0; i<n ;i++)
{
if (strcmp(a[i].DV ,"KHCB") == 0)
Xuat (a[i]);
}
}
main ()
{
NV a[MAX];
int n;
do
{
printf("\nNhap so luong NV : ");
scanf ("%d",&n);
if (n < 0 || n > MAX)
printf("\nXin nhap lai !");
}while (n < 0 || n > MAX);
//1//
Nhap2 (a,n);
//2//
printf ("\nDanh sach nv cua don vi \"KHCB\" la \n");
TimKiem (a,n);
//3//
printf ("\nDanh sach NV da nhap la : \n");
Xuat2 (a,n);
getch ();
}
--------------------------------------------------------------
Câu 3 : viết bằng C++
#include <iostream>
using namespace std;
#define MAX 1000
#include <string.h>
typedef struct NhanVien
{
char MaNV[40];
char TenNV[40];
char GT[4];
int NS;
char DV [40];
}NV;
void Nhap (NV &a)
{
cout<<"\nNhap Ma nv : "; fflush (stdin);gets (a.MaNV);
cout<<"\nNhap Ho Ten nv : ";fflush (stdin);gets (a.TenNV);
cout<<"\nNhap gioi tinh nv : ";fflush (stdin);gets (a.GT);
cout<<"\nNhap nam sinh cua nhan vien : ";cin>>a.NS;
cout<<"\nNhap don vi cu nhan vien : ";fflush (stdin);gets (a.DV);
cout<<"\n----------------";
}
void Xuat (NV a)
{
cout<<"\nMa nv : "; fflush (stdin);puts (a.MaNV);
cout<<"\nHo Ten nv : ";fflush (stdin);puts (a.TenNV);
cout<<"\\Gioi tinh nv : ";fflush (stdin);puts (a.GT);
cout<<"\nNam sinh cua nhan vien : ";cout<<a.NS;
cout<<"\nDon vi cu nhan vien : ";fflush (stdin);puts (a.DV);
cout<<"\n----------------";
}
void Nhap2 (NV a[], int &n)
{
for (int i = 0; i <n; i++)
{
cout<<"\nThong tin NV thu "<<i+1;
Nhap(a[i]);
}
}
void Xuat2 (NV a[], int n)
{
for (int i = 0; i <n; i++)
{
Xuat(a[i]);
}
}
void TimKiem (NV a[], int n)
{
for (int i =0; i<n ;i++)
{
if (strcmp(a[i].DV ,"KHCB") == 0)
Xuat (a[i]);
}
}
main ()
{
NV a[MAX];
int n;
do
{
cout<<"\nNhap so luong NV : ";
cin>>n;
if (n < 0 || n > MAX)
cout<<"\nXin nhap lai !";
}while (n < 0 || n > MAX);
//1//
Nhap2 (a,n);
//2//
cout<<"\nDanh sach nv cua don vi \"KHCB\" la :\n";
TimKiem (a,n);
//3//
cout<<"\nDanh sach NV da nhap la : \n";
Xuat2 (a,n);
system ("pause");
}
Câu 3 : viết bằng C++
#include <iostream>
using namespace std;
#define MAX 1000
#include <string.h>
typedef struct NhanVien
{
char MaNV[40];
char TenNV[40];
char GT[4];
int NS;
char DV [40];
}NV;
void Nhap (NV &a)
{
cout<<"\nNhap Ma nv : "; fflush (stdin);gets (a.MaNV);
cout<<"\nNhap Ho Ten nv : ";fflush (stdin);gets (a.TenNV);
cout<<"\nNhap gioi tinh nv : ";fflush (stdin);gets (a.GT);
cout<<"\nNhap nam sinh cua nhan vien : ";cin>>a.NS;
cout<<"\nNhap don vi cu nhan vien : ";fflush (stdin);gets (a.DV);
cout<<"\n----------------";
}
void Xuat (NV a)
{
cout<<"\nMa nv : "; fflush (stdin);puts (a.MaNV);
cout<<"\nHo Ten nv : ";fflush (stdin);puts (a.TenNV);
cout<<"\\Gioi tinh nv : ";fflush (stdin);puts (a.GT);
cout<<"\nNam sinh cua nhan vien : ";cout<<a.NS;
cout<<"\nDon vi cu nhan vien : ";fflush (stdin);puts (a.DV);
cout<<"\n----------------";
}
void Nhap2 (NV a[], int &n)
{
for (int i = 0; i <n; i++)
{
cout<<"\nThong tin NV thu "<<i+1;
Nhap(a[i]);
}
}
void Xuat2 (NV a[], int n)
{
for (int i = 0; i <n; i++)
{
Xuat(a[i]);
}
}
void TimKiem (NV a[], int n)
{
for (int i =0; i<n ;i++)
{
if (strcmp(a[i].DV ,"KHCB") == 0)
Xuat (a[i]);
}
}
main ()
{
NV a[MAX];
int n;
do
{
cout<<"\nNhap so luong NV : ";
cin>>n;
if (n < 0 || n > MAX)
cout<<"\nXin nhap lai !";
}while (n < 0 || n > MAX);
//1//
Nhap2 (a,n);
//2//
cout<<"\nDanh sach nv cua don vi \"KHCB\" la :\n";
TimKiem (a,n);
//3//
cout<<"\nDanh sach NV da nhap la : \n";
Xuat2 (a,n);
system ("pause");
}
0 comments:
Post a Comment