1.
#include<iostream>
using namespace std;
int main(){
double a,b,h;
cout<<"Do dai canh day lan luot la: ";
cin>>a>>b;
cout<<"Do dai chieu cao la: ";cin>>h;
cout<<"Dien tich hinh thang la: "<<h*((a+b)/2);
return 0;
}
2.
#include<iostream>
using namespace std;
int main(){
int a,b;
cout<<"Nhap a = ";cin>>a;
cout<<"Nhap b = ";cin>>b;
a=a+b;
b=a-b;
a=a-b;
cout<<"a = "<<a<<" , "<<"b= "<<b;
return 0;
}
3.
#include<iostream>
using namespace std;
int main(){
int n,d=0,S=0,a;
cin>>n;
for (int i=0;i<n;i++){
a=i;
while(a>0){
d=d*10+a;
a=a/10;
}
if(i==d){
S+=i;
}
d=0;
}
cout<<S;
return 0;
}
5.
#include<iostream>
using namespace std;
int main(){
int a[100],n,d=0,sum=0,dem=0;
cin>>n;
for (int i=0;i<n;i++){
cin>>a[i];
}
for (int i=0;i<n;i++){
for(int v=1;v<a[i];v++){
if (a[i]%v==0){
d++;
}
}
if(d==1){
dem++;
sum+=a[i];
}
d=0;
}
cout<<"Co "<<dem<<" so nguyen to"<<endl;
cout<<"Tong cac so nguyen to la: "<<sum;
return 0;
}
6.
#include<iostream>
using namespace std;
int main(){
int n,a[100],g=0,s=0,b;
cin>>n;
for(int i=0;i<n;i++){
cin>>a[i];
}
for(int i=0;i<n;i++){
for(int v=1;v<a[i];v++){
if(a[i]%v==0){
s+=v;
}
}
if(s==a[i]){
for(int f=i+1;f<n;f++){
for(int z=1;z<a[f];z++){
if(a[f]%z==0){
g+=z;
}
}
if(a[f]==g){
if(a[i]>a[f]){
b=a[f];
a[f]=a[i];
a[i]=b;
}
}
g=0;
}
}
s=0;
}
for(int i=0;i<n;i++){
cout<<a[i]<<" ";
}
return 0;
}