admin admin Author
Title: [C]-- Chữa đề thi kết thúc học phần Nhập Môn Tin Học ĐH Điện Lực
Author: admin
Rating 5 of 5 Des:
Câu 1 :   Viết bằng ngôn nghữ C #include <stdio.h> #include <coio.h> #include math.h> int GiaiThua (int a) { if (a ...
Câu 1 : Viết bằng ngôn nghữ C
#include <stdio.h>
#include <coio.h>
#include math.h>
int GiaiThua (int a)
{
 if (a < 2)
  return 1;
 if (a > 1)
 return a * GiaiThua (a-1);
}
 int Tinh (int &n)
{
 int Tong = 0;
 for (int i = 1;i <=n;i++)
 {
  Tong+= pow (-1,i-1)*GiaiThua (i);
 }
 return Tong;
}
main ()
{
 int n;
 printf ("\nNhap n = ");
 scanf ("%d",&n);
 printf ("\nTong  =  %d",Tinh (n));
 getch ();
 
}
 

------------------------------------------------------------------

Câu 1 : Viết bằng ngôn nghữ C++
#include 
using namespace std;
#include 

//Ham tinh giai thua
int GiaiThua (int a)
{
 if (a < 2)
  return 1;
 if (a > 1)
 return a * GiaiThua (a-1);
}

int Tinh (int &n)
{
 int Tong = 0;
 for (int i = 1;i <=n;i++)
 {
  Tong+= pow (-1,i-1)*GiaiThua (i);
 }
 return Tong;
}
main ()
{
 int n;
 cout<<"\nNhap n = ";
 cin>>n;
 cout<<"\nTong  =  "<



---------------------------------------------------------

Câu 2 : Viết bằng ngôn nghữ C
#include <stdio.h>
#include <conio.h>
#include <math.h>
#define MAX 100
void Nhap (char S[])
{
 printf ("\nXau can nhap la : ");
 fflush (stdin);
 gets (S);
}
void Xuat (char S[])
{

 fflush (stdin);
 puts (S);
}

void Them (char S[])
{
 strcat (S,"abc");
 printf ("\nChuoi sau khi noi them \"abc\" co dang : ");
 Xuat (S);
}
int Dem (char S[])
{
 int l = strlen (S);
 return l;
}

main ()
{
 char S[MAX];

 //1//
 Nhap (S);

 //2//
 printf ("\nChuoi vua nhap la : ");
 Xuat (S);

 //3//
 printf ("\nChieu dai cua chuoi vua nhap la : %d",Dem (S));

 //4//
 Them (S);

 getch ();


}






---------------------------------------------------

Câu 2 : Viết bằng ngôn nghữ C++
#include 
using namespace std;
#include 
#define MAX 100
void Nhap (char S[])
{
 cout<<"\nXau can nhap la : ";
 fflush (stdin);
 gets (S);
}
void Xuat (char S[])
{

 fflush (stdin);
 puts (S);
}

void Them (char S[])
{
 strcat (S,"abc");
 cout<<"\nChuoi sau khi noi them \"abc\" co dang : ";
 Xuat (S);
}
int Dem (char S[])
{
 int l = strlen (S);
 return l;
}

main ()
{
 char S[MAX];

 //1//
 Nhap (S);

 //2//
 cout<<"\nChuoi vua nhap la : ";
 Xuat (S);

 //3//
 cout<<"\nChieu dai cua chuoi vua nhap la : "<



----------------------------------------------

Câu 3 : Viết bằng ngôn nghữ C
#include <stdio.h>
#include <conio.h>
#define MAX 1000
#include 
typedef struct ThuVien
{
 char MaS [20];
 char TenS[40];
 char MaNXB[20];
 int Sl;
}TV;

void Nhap (TV &a)
{
 printf ("\nNhap ma sach : ");fflush (stdin);gets(a.MaS);
 printf ("\nNhap ten sach : ");fflush (stdin);gets (a.TenS);
 printf ("\nNhap ma nxb : ");fflush (stdin);gets (a.MaNXB);
 printf ("\nSo luong sach : ");scanf ("%d",&a.Sl);
 printf ("\n----------------");
}
void Xuat (TV a)
{
 printf ("\n ma sach : ");fflush (stdin);puts(a.MaS);
 printf ("\n ten sach : ");fflush (stdin);puts (a.TenS);
 printf ("\n ma nxb : ");fflush (stdin);puts (a.MaNXB);
 printf ("\nSo luong sach : ");printf ("%d",a.Sl);
 printf ("\n----------------");
}
void Nhap2 (TV a[], int &n)
{
 for (int i = 0; i  500)
  Xuat(a[i]);
 }
}

main ()
{
 TV a[MAX];
 int n;
 do
 {
  printf ("\nNhap so luong sach cua thu vien co : ");
  scanf ("%d",&n);
  if (n < 0 || n > MAX)
  printf ("\nXin nhap lai !");
 }while (n < 0 || n > MAX);

 //1.
 Nhap2 (a,n);

 //2.
 printf ("\nSo Sach cua NXB \"MNXB084\" la : %d",Dem (a,n));

 //3.
 printf ("\nCac loai sach co sl > 500 la :\n");
 TimKiem (a,n);
 getch ();

}


----------------------------------------------------

Câu 3 : Viết bằng ngôn nghữ C++
#include 
using namespace std;
#define MAX 1000
#include 
typedef struct ThuVien
{
 char MaS [20];
 char TenS[40];
 char MaNXB[20];
 int Sl;
}TV;

void Nhap (TV &a)
{
 cout <<"\nNhap ma sach : ";fflush (stdin);gets(a.MaS);
 cout <<"\nNhap ten sach : ";fflush (stdin);gets (a.TenS);
 cout <<"\nNhap ma nxb : ";fflush (stdin);gets (a.MaNXB);
 cout <<"\nSo luong sach : ";cin>>a.Sl;
 cout <<"\n----------------";
}
void Xuat (TV a)
{
 cout <<"\n ma sach : ";fflush (stdin);puts(a.MaS);
 cout <<"\n ten sach : ";fflush (stdin);puts (a.TenS);
 cout <<"\n ma nxb : ";fflush (stdin);puts (a.MaNXB);
 cout <<"\nSo luong sach : ";cout < 500)
  Xuat(a[i]);
 }
}

main ()
{
 TV a[MAX];
 int n;
 do
 {
  cout<<"\nNhap so luong sach cua thu vien co : ";
  cin>>n;
  if (n < 0 || n > MAX)
  cout<<"\nXin nhap lai !";
 }while (n < 0 || n > MAX);

 //1.
 Nhap2 (a,n);

 //2.
 cout<<"\nSo Sach cua NXB \"MNXB084\" la : "< 500 la :\n";
 TimKiem (a,n);
 system ("pause");
}





About Author

Advertisement

Post a Comment

 
Top