0% found this document useful (0 votes)
13 views9 pages

Bài 1

Uploaded by

nogoshplzno12345
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)
13 views9 pages

Bài 1

Uploaded by

nogoshplzno12345
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/ 9

Dạng if, for, while:

Bài 1:

#include <bits/stdc++.h>

#define ll long long

using namespace std;

ll n,i=2;

int main()

cin>>n;

while (n>1)

while (n%i==0)

cout<<i<<" ";

n/=i;

i++;

return 0;

Bài 2:

#include <bits/stdc++.h>

#define ll long long

using namespace std;

ll n,m;

int main()

{
cin>>n>>m;

for (int i=1;i<=n;i++)

for (int j=1;j<=m;j++)

cout<<"#";

cout<<'\n';

return 0;

Bài 3:

#include <bits/stdc++.h>

#define ll long long

using namespace std;

ll a,b,c;

int main()

cin>>a>>b>>c;

if (a>b&&b>c)

cout<<c<<" "<<a;

else

if (b>a&&a>c)

cout<<c<<" "<<b;

else

if (c>b&&b>a)

cout<<a<<" "<<c;
else

if (b>c&&c>a)

cout<<a<<" "<<b;

else

if (c>a&&a>b)

cout<<b<<" "<<c;

else

if (a>c&&c>b)

cout<<b<<" "<<a;

return 0;

Bai4:

Chia táo:

#include <bits/stdc++.h>

using namespace std;

long long n,m;

int main()

{
cin>>n>>m;

cout<<(n-n%m)/m;

return 0;

Bai5 vd001:

#include <bits/stdc++.h>

using namespace std;

long long n,m;

int main()

cin>>n>>m;

cout<<m+n;

return 0;

Bai6

A cộng B:

#include <bits/stdc++.h>

using namespace std;


long long n,m,a,b;
int main()
{
cin>>n;
for (int i=1;i<=n;i++)
{
cin>>a>>b;
cout<<a+b<<'\n';
}
return 0;
}
Bai7:

Số nguyên tố

#include <bits/stdc++.h>

using namespace std;

long long n,a;

bool t;

int main()

cin>>n;

for (int i=2;i<=sqrt(n);i++)

if (n%i!=0)

t=true;

else

t=false;

a=i;

break;

if (t==true)

cout<<"YES";

else cout<<a;

return 0;

Bai 8:
In dãy #2

#include <bits/stdc++.h>

using namespace std;

long long n;

int main()

cin>>n;

for (int i=1;i<=n;i++)

cout<<(i+1)*i/2<<'\n';

return 0;

Bai9:

Vẽ tam giác vuông cân:

#include <bits/stdc++.h>

using namespace std;

long long n,j;

int main()

cin>>n;

j=n;

for (int i=n;i>=1;i--)

for (int j=i;j>=1;j--)

cout<<"*";
}

cout<<endl;

return 0;

Bai10:

Phân tích #3

#include <bits/stdc++.h>

using namespace std;

long long n;

double t,t1;

int main()

cin>>n;

while (n>0)

t+=n%10;

n/=10;

t1++;

double t2=t/t1;

cout<<setprecision(2)<<fixed<<t2;

return 0;

Bai11:
So sánh #4 :

#include <bits/stdc++.h>

using namespace std;

long long a[6];

int main()

for (int i=1;i<=5;i++)

cin>>a[i];

sort (a+1,a+6);

cout<<a[5];

return 0;

Bai12:

cdl2p9:

#include <bits/stdc++.h>

using namespace std;

long long a[3];

int main()

for (int i=0;i<3;i++)

cin>>a[i];

sort (a,a+3);

cout<<a[2];

return 0;

}
Bai13:

cdl2p8:

#include <bits/stdc++.h>

using namespace std;

double a[3];

int main()

for (int i=0;i<3;i++)

cin>>a[i];

sort (a,a+3);

cout<<a[1];

return 0;

Bai14:

Cánh diều - CAPHE - Sản lượng cà phê

#include <bits/stdc++.h>

using namespace std;


double tsl,slarabica,t;
int main()
{
cin>>tsl>>slarabica;
t=slarabica/tsl;
if(t<0.1)
cout<<"Arabica mat mua."<<'\n'<<"He so gia ban: "<<3;
else
cout<<"Arabica duoc mua."<<'\n'<<"He so gia ban: "<<2;
return 0;
}

You might also like