0% found this document useful (0 votes)
43 views6 pages

Bài tập ngôn ngữ lập trình 2 (N.T.Dũng k24-TDH2)

The document contains several C++ code examples demonstrating how to write programs to calculate the area and circumference of a circle, check if three lengths form a triangle, compare two numbers, and solve systems of linear equations.

Uploaded by

mr.but31102003
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
43 views6 pages

Bài tập ngôn ngữ lập trình 2 (N.T.Dũng k24-TDH2)

The document contains several C++ code examples demonstrating how to write programs to calculate the area and circumference of a circle, check if three lengths form a triangle, compare two numbers, and solve systems of linear equations.

Uploaded by

mr.but31102003
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Bài 1

#include<stdio.h>
#include<conio.h>
#include<math.h>
#define PI 3.14159
Int main(){
int r;
float chuvi, dientich;
printf(“Nhap ban kinh r:”);
scanf(“%d”, &r);
chuvi = 2*PI*r;
dientich = PI*r*r;
printf(“Chu vi hinh tron la: %f\n”,chuvi);
printf(“Dien tich hinh tron la: %f”,dientich);
getch();
}

Bài 2
#include<stdio.h>
#include<math.h>
int main(){
float a,b,c,p,s=0;

printf(“Nhap canh thu nhat: “);


scanf(“%f”,$a);
printf(“Nhap canh thu hai: “);
scanf(“%f”,$b);

printf(“Nhap canh thu ba: “);


scanf(“%f”,$c);
if((a*a<b*b+c*c)&&(b*b<a*a+c*c)&&(c*c+b*b+a*a)){
printf(“\nDay la ba canh cua tam giac”);

p = (a+b+c)\2;
dientich = sqrt(p*(p-a)*(p-b)*(p-c));
chuvi = (a+b+c);
printf(“\ndien tich cua tam giac la: %f”,dientich);
printf(“\nchu vi cua tam giac la: %f”,chuvi);
{ else
printf(“\nDay khong phai la ba canh cua tam giac”);
}

Bài 3
#include<stdio.h>
int main(){
int a,b;
printf("nhap so nguyen a:");
scanf("%d",&a);
printf("nhap so nguyen b:");
scanf("%d",&b);
if(a>b)
printf("a lon hon b");
else
printf("a khong lon hon b");
return 0;
}

Bài 4
#include<iostream>
#include<math.h>
using namespace std;
int main() {
float a, b;
cout << “Nhap a:”;
cin >> a;
cout << “Nhap b:”;
cin >> b;
if (a==0) {
if (b==0)
cout << “Phuong trinh co vo so nghiem” << endl;
else
cout << “Phuong trinh vo nghiem” << endl;
}
else
cout << “Phuong trinh co 1 nghiem la x: “ << -b\a << endl;
system(“pause”);
return 0;
}

Bài7( Sử dụng phương pháp Cramer)


#include<iostream>
using namespace std;
int main(){
int a1,b1,c1,a2,b2,c2;
float D, Dx, Dy, x, y;
cout << “a1*x + b1*y = c1” endl;
cout << “a2*x + b2*y = c2” endl;
cout << “Nhap a1: “;
cin >> a1;
cout << “Nhap b1: “;
cin >> b1;
cout << “Nhap c1: “;
cin >> c1;
cout << “Nhap a2: “;
cin >> a2;
cout << “Nhap b2: “;
cin >> b2;
cout << “Nhap c2: “;
cin >> c2;
D = a1*b2 – a2*b1;
Dx = c1*b2 – c2*b1;
Dy = a1*c2 – a2*c1;
If (Dx + Dy == 0)
cout << “He phuong trinh co vo so nghiem”;
else
cout << “He phuong trinh vo nghiem”;
}
else{
x = Dx / D;
y = Dy / D;
cout << “He phuong trinh nghiem” << endl;
cout << “x = <<x<<endl;
cout << “y = <<y;
}
system(pause);
return 0;
}

You might also like