peri hokiperihokiclarustologisticsrimashaop.compola taktis menang gates of olympus x1000 perihokipemain perihoki bongkar trik jepep starlight princess x1000perihoki beri panduan lengkap bermain mahjong ways 2 pgsofttips cara penghasil uang pgsoft mahjong ways 2 perihokimahjong wins 3 perihoki memberikan penggali terbesarfenomena gates of olympus buka peluang besar bagi duta76cara dapat pola emas rahasia di duta7 wild west goldtrik menang pgsoft mahjong ways 2 modal receh maxwin duta76duta76 main pgsoft mahjong ways 2 di sela istirahatscatter hitam mahjong wins 3 spin pasti jepe duta76perihoki spin mahjong ways 2 pgsoft scatter hitam maxwinsimbol mahjong wins 3 yang sering muncul di awal perihokitrik gampang menang mahjong winscuan mahjong wins 3 tanpa hentipola spin taruhan kecil mahjong winsstrategi kunci scatter hitam beruntungacor total mahjong wayskemenangan maksimal mahjong wayskemenangan pria pekanbaru mahjong waysmahjong wins3 fenomena baru sumatera baratmenangkan mahjong dengan lincahmenembus batas keberuntungan mahjong waysmenjajal keberuntungan di mahjong wayspola gratis mahjong ways1scatter hitam senjata rahasia mahjong winsteknik spinning menguntungkan untuk scatter hitamanalisis rtp tertinggi mahjong winsfenomena scatter hitam mahjong winsibu rumah tangga dan keberuntungan mahjongkeseruan main mahjong wins3menang mahjong pengguna baru di sosial mediamenghargai setiap momen di mahjong waysserunya main mahjong di warung internetspin slow motion mancing scatterstrategi jitu maxwin mahjong waysstrategi jitu menang mahjong modal kecil jackpot besaranak kampung papua menggemparkan mahjongkeajaiban scatter hitam mahjong wayskeberhasilan joni mahjong winskejaiban mahjong ways di ujung jalanketua mahjong wins3 kehadiran kemenangan dimulai dari balimahjong kehadiran yang menguntungkanmahjong menggila adat88panduan kilat raih 108 jutatips memenangkan mahjongbarista kopi menang 110 juta spin mahjongdakota76 scatter hitam mahjong wins 3gagal cpns menang mahjong wins 3 rp120 jutakisah karyawan minimarket dapat thr lebih awal mahjong winskisah pelajar sma kuasai mahjong wins 3 inspirasi sekolahkisah penjaga parkir tanah abang motor baru mahjong winskisah sukses ibu rumah tangga bandung mahjong winsmahasiswa kkn beli iphone15 mahjong wins3 dakotamantan anak band influencer mahjong scatter hitampola rtp senin gates of olympus guru matematikatukang cuci motor menemukan keberuntungan di mahjong
A PHP Error was encountered
Severity: Warning
Message: ini_set(): Headers already sent. You cannot change the session module's ini settings at this time
Filename: Session/Session.php
Line Number: 282
Backtrace:
File: /home/blogchuabenh/domains/freetuts.net/public_html/site/controllers/Main_controller.php
Line: 10
Function: __construct
File: /home/blogchuabenh/domains/freetuts.net/public_html/sources/index.php
Line: 299
Function: require_once
File: /home/blogchuabenh/domains/freetuts.net/public_html/index.php
Line: 26
Function: require_once
A PHP Error was encountered
Severity: Warning
Message: session_set_cookie_params(): Cannot change session cookie parameters when headers already sent
Filename: Session/Session.php
Line Number: 294
Backtrace:
File: /home/blogchuabenh/domains/freetuts.net/public_html/site/controllers/Main_controller.php
Line: 10
Function: __construct
File: /home/blogchuabenh/domains/freetuts.net/public_html/sources/index.php
Line: 299
Function: require_once
File: /home/blogchuabenh/domains/freetuts.net/public_html/index.php
Line: 26
Function: require_once
A PHP Error was encountered
Severity: Warning
Message: ini_set(): Headers already sent. You cannot change the session module's ini settings at this time
Filename: Session/Session.php
Line Number: 304
Backtrace:
File: /home/blogchuabenh/domains/freetuts.net/public_html/site/controllers/Main_controller.php
Line: 10
Function: __construct
File: /home/blogchuabenh/domains/freetuts.net/public_html/sources/index.php
Line: 299
Function: require_once
File: /home/blogchuabenh/domains/freetuts.net/public_html/index.php
Line: 26
Function: require_once
A PHP Error was encountered
Severity: Warning
Message: ini_set(): Headers already sent. You cannot change the session module's ini settings at this time
Filename: Session/Session.php
Line Number: 314
Backtrace:
File: /home/blogchuabenh/domains/freetuts.net/public_html/site/controllers/Main_controller.php
Line: 10
Function: __construct
File: /home/blogchuabenh/domains/freetuts.net/public_html/sources/index.php
Line: 299
Function: require_once
File: /home/blogchuabenh/domains/freetuts.net/public_html/index.php
Line: 26
Function: require_once
A PHP Error was encountered
Severity: Warning
Message: ini_set(): Headers already sent. You cannot change the session module's ini settings at this time
Filename: Session/Session.php
Line Number: 315
Backtrace:
File: /home/blogchuabenh/domains/freetuts.net/public_html/site/controllers/Main_controller.php
Line: 10
Function: __construct
File: /home/blogchuabenh/domains/freetuts.net/public_html/sources/index.php
Line: 299
Function: require_once
File: /home/blogchuabenh/domains/freetuts.net/public_html/index.php
Line: 26
Function: require_once
A PHP Error was encountered
Severity: Warning
Message: ini_set(): Headers already sent. You cannot change the session module's ini settings at this time
Filename: Session/Session.php
Line Number: 316
Backtrace:
File: /home/blogchuabenh/domains/freetuts.net/public_html/site/controllers/Main_controller.php
Line: 10
Function: __construct
File: /home/blogchuabenh/domains/freetuts.net/public_html/sources/index.php
Line: 299
Function: require_once
File: /home/blogchuabenh/domains/freetuts.net/public_html/index.php
Line: 26
Function: require_once
A PHP Error was encountered
Severity: Warning
Message: ini_set(): Headers already sent. You cannot change the session module's ini settings at this time
Filename: Session/Session.php
Line Number: 317
Backtrace:
File: /home/blogchuabenh/domains/freetuts.net/public_html/site/controllers/Main_controller.php
Line: 10
Function: __construct
File: /home/blogchuabenh/domains/freetuts.net/public_html/sources/index.php
Line: 299
Function: require_once
File: /home/blogchuabenh/domains/freetuts.net/public_html/index.php
Line: 26
Function: require_once
A PHP Error was encountered
Severity: Warning
Message: ini_set(): Headers already sent. You cannot change the session module's ini settings at this time
Filename: Session/Session.php
Line Number: 375
Backtrace:
File: /home/blogchuabenh/domains/freetuts.net/public_html/site/controllers/Main_controller.php
Line: 10
Function: __construct
File: /home/blogchuabenh/domains/freetuts.net/public_html/sources/index.php
Line: 299
Function: require_once
File: /home/blogchuabenh/domains/freetuts.net/public_html/index.php
Line: 26
Function: require_once
A PHP Error was encountered
Severity: Warning
Message: ini_set(): Headers already sent. You cannot change the session module's ini settings at this time
Filename: drivers/Session_files_driver.php
Line Number: 108
Backtrace:
File: /home/blogchuabenh/domains/freetuts.net/public_html/site/controllers/Main_controller.php
Line: 10
Function: __construct
File: /home/blogchuabenh/domains/freetuts.net/public_html/sources/index.php
Line: 299
Function: require_once
File: /home/blogchuabenh/domains/freetuts.net/public_html/index.php
Line: 26
Function: require_once
A PHP Error was encountered
Severity: Warning
Message: session_set_save_handler(): Cannot change save handler when headers already sent
Filename: Session/Session.php
Line Number: 110
Backtrace:
File: /home/blogchuabenh/domains/freetuts.net/public_html/site/controllers/Main_controller.php
Line: 10
Function: __construct
File: /home/blogchuabenh/domains/freetuts.net/public_html/sources/index.php
Line: 299
Function: require_once
File: /home/blogchuabenh/domains/freetuts.net/public_html/index.php
Line: 26
Function: require_once
A PHP Error was encountered
Severity: Warning
Message: session_start(): Cannot start session when headers already sent
Filename: Session/Session.php
Line Number: 143
Backtrace:
File: /home/blogchuabenh/domains/freetuts.net/public_html/site/controllers/Main_controller.php
Line: 10
Function: __construct
File: /home/blogchuabenh/domains/freetuts.net/public_html/sources/index.php
Line: 299
Function: require_once
File: /home/blogchuabenh/domains/freetuts.net/public_html/index.php
Line: 26
Function: require_once
C++ - Tìm số lớn nhất trong 3 số được nhập từ bàn phím.
STARTING
CONTROL STATEMENT
FUNCTION
ARRAY & POINTER
OOP
STL
ITERATORS
OTHER FEATURES
CÁC CHỦ ĐỀ
BÀI MỚI NHẤT
C++ - Tìm số lớn nhất trong 3 số được nhập từ bàn phím.
Tìm số lớn nhất trong 3 số được nhập từ bàn phím.
Bài giải
-------------------- ######## --------------------
Cách giải bài toán này đơn giản như sau:

Bài viết này được đăng tại freetuts.net, không được copy dưới mọi hình thức.
- Lấy một biến tạm giữ giá trị lớn nhất, ta gọi đó là max
- Gán giá trị số đầu tiên cho max, bây giờ max là số đầu tiên
- So sánh max với số thứ 2, nếu số thứ 2 lớn hơn max, gán giá trị max bằng số thứ 2
- So sánh max với số thứ 3, nếu số thứ 3 lớn hơn max, gán giá trị max bằng số thứ 3
Chúng ta sẽ sử dụng cấu trúc điều khiển if else trong C++ để giải quyết bài toán trên như sau:
#include <iostream>
using namespace std;
int main()
{
int a, b, c, max;
cout << "Nhap a = ";
cin >> a;
cout << "Nhap b = ";
cin >> b;
cout << "Nhap c = ";
cin >> c;
max = a;
if(max < b) {
max = b;
}
if(max < c) {
max=c;
}
cout << "So lon nhat trong 3 so " << a << ", " << b << ", " << c << " la: " << max;
return 0;
}
Và kết quả sau khi thực thi chương trình trên như sau:
Khi nhập a = 5, b = 3 và c = 7:
Bài viết này được đăng tại [free tuts .net]

Khi nhập a = 1, b = 5, và c = 2:

Khi nhập a = 6, b = 3, và c = 2:

8. Bài tập if else C++
Cùng chuyên mục: