Bài tập C++
Bai 2
#include<cstdlib>
#include<iostream>
using namespace std;
int main()
{
int i,N,s=0,tong=0;
cout<<"Hay nhap so N:";
cin>>N;
cout<<endl;
for(i=1;i<N;i++)
if(N%i==0)
{
s++;
tong=tong+i;
}
cout<<s<<endl;
cout<<tong<<endl;
system("pause");
return 0;
}
Bai 6
#include<cstdlib>
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
int a,b,c;
cout<<"nhap vao 3 nguyen a, b, c:";
cin>>a>>b>>c;
if (a>b)
if (b>c)
cout<<c<<" "<<b<<" "<<a;
else
if (a>c)
cout<<b<<" "<<c<<" "<<a;
else cout<<b<<" "<<a<<" "<<c;
else
if (b<c)
cout<<a<<" "<<b<<" "<<c;
else
if (a<c)
cout<<a<<" "<<c<<" "<<b;
else cout<<c<<" "<<a<<" "<<b;
system("pause");
return 0;
}
Bai 4
#include<cstdlib>
#include<iostream>
using namespace std;
int main()
{
int i,N,M,s,dem=0;
N!=M;
cout<<"Hay nhap N,M (dk N # M ):";
cin>>N>>M;
if (N>M)
{
for(i=1;i<=M;i++)
if (((N%i)==0)&&((M%i)==0))
dem++ ;
cout<<dem<<endl;
}
else
{
for(i=1;i<=N;i++)
if(((N%i)==0)&&((M%i)==0))
dem++;
cout<<dem<<endl;
}
system("pause");
return 0;
}
Bạn đang đọc truyện trên: Truyen247.Pro