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 matematikaidola scatter hitam gampang meledakidola sensasi jackpotidola pola scatter hitamidola hasilkan jackpot dalam waktu singkatidola mahjong wins 3 bocortukang 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

Kiểm tra tháng thuộc quý nào bằng C / C++
SIMPLE
STRING
ARRAY
SORTING
POINTER
CALCULATION
NUMBER
OTHER
CÁC CHỦ ĐỀ
BÀI MỚI NHẤT
MỚI CẬP NHẬT

Kiểm tra tháng thuộc quý nào bằng C / C++

Trong bải viết này chúng ta sẽ thực hiện chương trình kiểm tra một tháng trong năm thuộc quý bao nhiêu bằng C / C++.

test php

banquyen png
Bài viết này được đăng tại freetuts.net, không được copy dưới mọi hình thức.

Mình sẽ thực hiện hai chương trình để kiểm tra bằng hai ngôn ngữ khác nhau là C và C++, vì vậy các bạn cần có kiến thức cơ bản về hai ngôn ngữ này.

Kiểm tra một tháng trong năm thuộc quý bao nhiều bằng C

Để kiểm tra một tháng trong năm thuộc quý bao nhiêu bằng C thì việc đầu tiên ta cần có tháng cần kiểm tra. Vì vậy sẽ khai báo biến month sau đó sử dụng printf() và scanf() để yêu cầu người dùng nhập vào tháng cần kiểm tra.

Tiếp đến sử dụng switch case để kiểm tra tháng vừa được nhập vào:

Bài viết này được đăng tại [free tuts .net]

  • Nếu người dùng nhập vào 1, 2, 3 thì thông báo thuộc quý 1.
  • Nếu người dùng nhập vào 4, 5, 6 thì thông báo thuộc quý 2.
  • Nếu người dùng nhập vào 7, 8, 9 thì thông báo thuộc quý 3.
  • Nếu người dùng nhập vào 10, 11, 12 thì thông báo thuộc quý 4.
  • Nếu người dùng nhập vào <= 0 và > 12 thì thông báo đã nhập sai.

Dưới đây là chương trình kiểm tra một tháng trong năm thuộc quý bao nhiêu mà mình đã viết sẵn bằng ngôn ngữ C, các bạn có thể tham khảo nhé!

#include<stdio.h>
int main()
{
  //khai báo biến month là tháng cần kiểm tra quý
  int month;
  //sử dụng printf() và scanf() để yêu cầu người dùng nhập vào tháng cần kiểm tra
  printf("\nNhập vào một tháng bất kỳ cần kiểm tra: ");
  scanf("%d", &month);
  //sử dụng switch case để kiểm tra các trường hợp
  switch (month)
  {
    //nếu người dùng nhập vào 1, 2, 3 thì thông báo thuộc quý 1
    case 1:
    case 2:
    case 3:
      printf("\nTháng %d thuộc quý 1", month);
      break;
    //nếu người dùng nhập và 4, 5, 6 thì thông báo thuộc quý 2
    case 4:
    case 5:
    case 6:
      printf("\nTháng %d thuộc quý 2", month);
      break;
    //nếu người dùng nhập vào 7, 8, 9 thì thông báo thuộc quý 3
    case 7:
    case 8:
    case 9:
      printf("\nTháng %d thuộc quý 3", month);
      break;
    //nếu người dùng nhập vào 10, 11, 12 thì thông báo thuộc quý 4
    case 10:
    case 11:
    case 12:
      printf("\nTháng %d thuộc quý 4", month);
      break;
    //các trường hợp còn lại thì yếu cầu người dùng nhập lại vì đã nhập sai
    default:
      printf("Vui lòng nhập tháng từ 1 -> 12");
      break;
  }
  printf("\n----------------------------------------\n");
  printf("Chương trình này được đăng tại Freetuts.net");
}

Kết quả:

bai36 01 PNG

Kiểm tra một tháng trong năm thuộc quý bao nhiêu bằng C++

Để kiểm tra một tháng trong năm thuộc quý bao nhiều bằng C++ cũng tương tự như việc kiểm tra bằng ngôn ngữ C, vì về cơ bản thì hai ngôn ngữ này khá tương đồng nhau.

Các bạn chỉ cần thay thế printf() và scanf() trong ngôn ngữ C bằng cout() và cin() trong ngôn ngữ C++. Nhớ khai báo thư viện <iostream> trước khi sử dụng cout() và cin() nhé.

#include<iostream>
using namespace std;
int main()
{
  //khai báo biến month là tháng cần kiểm tra quý
  int month;
  //sử dụng cout() và cin() để yêu cầu người dùng nhập vào tháng cần kiểm tra
  cout<<"\nNhập vào một tháng bất kỳ cần kiểm tra: ";
  cin>>month;
  //sử dụng switch case để kiểm tra các trường hợp
  switch (month)
  {
    //nếu người dùng nhập vào 1, 2, 3 thì thông báo thuộc quý 1
    case 1:
    case 2:
    case 3:
      cout<<"\nTháng "<<month<<" thuộc quý 1";
      break;
    //nếu người dùng nhập và 4, 5, 6 thì thông báo thuộc quý 2
    case 4:
    case 5:
    case 6:
      cout<<"\nTháng "<<month<<" thuộc quý 2";
      break;
    //nếu người dùng nhập vào 7, 8, 9 thì thông báo thuộc quý 3
    case 7:
    case 8:
    case 9:
      cout<<"\nTháng "<<month<<" thuộc quý 3";
      break;
    //nếu người dùng nhập vào 10, 11, 12 thì thông báo thuộc quý 4
    case 10:
    case 11:
    case 12:
      cout<<"\nTháng "<<month<<" thuộc quý 4";
      break;
    //các trường hợp còn lại thì yếu cầu người dùng nhập lại vì đã nhập sai
    default:
      cout<<"Vui lòng nhập tháng từ 1 -> 12";
      break;
  }
  cout<<"\n----------------------------------------\n";
  cout<<"Chương trình này được đăng tại Freetuts.net";
}

Kết quả:

bai36 02 PNG

Như vậy là chúng ta đã thực hiện xong chương trình kiểm tra một tháng trong năm thuộc quý bao nhiêu bằng C / C++. Các bạn có thể tham khảo các bài tập khác tại Tổng hợp 1000 bài tập C / C++ nhé, chúc các bạn thành công !!!

Câu hỏi thường gặp liên quan:

Cùng chuyên mục:

Các hàm xử lý mảng đa chiều (array.h) trong C/C++

Các hàm xử lý mảng đa chiều (array.h) trong C/C++

Các hàm xử lý ngày tháng (datetime.h) trong C/C++

Các hàm xử lý ngày tháng (datetime.h) trong C/C++

Các hàm xử lý số thực (float.h) trong C/C++

Các hàm xử lý số thực (float.h) trong C/C++

Các hàm xử lý số nguyên lớn (bigint.h) trong C/C++

Các hàm xử lý số nguyên lớn (bigint.h) trong C/C++

Các hàm xử lý thời gian (time.h) trong C

Các hàm xử lý thời gian (time.h) trong C

Các hàm xử lý chuỗi (string.h) trong C/C++

Các hàm xử lý chuỗi (string.h) trong C/C++

Thread Pools và Parallel Algorithms trong C++

Thread Pools và Parallel Algorithms trong C++

Tạo và quản lý các Multithreading trong C++

Tạo và quản lý các Multithreading trong C++

Xử lý ngoại lệ khi làm việc với Memory Allocation trong C++

Xử lý ngoại lệ khi làm việc với Memory Allocation trong C++

Try, Catch, và Throw của Exception Handling trong C++

Try, Catch, và Throw của Exception Handling trong C++

Cách sử dụng Lambda Expressions trong C++

Cách sử dụng Lambda Expressions trong C++

Sử dụng weak_ptr trong C++

Sử dụng weak_ptr trong C++

Sử dụng shared_ptr trong C++

Sử dụng shared_ptr trong C++

Sử dụng unique_ptr trong C++

Sử dụng unique_ptr trong C++

Tổng quan về Smart Pointers trong C++

Tổng quan về Smart Pointers trong C++

Sử dụng Iterators trong STL của C++

Sử dụng Iterators trong STL của C++

[Iterator] Sử dụng Vector trong C++

[Iterator] Sử dụng Vector trong C++

[Iterator] Sử dụng trong List trong C++

[Iterator] Sử dụng trong List trong C++

[STL] Sử dụng Vector trong C++

[STL] Sử dụng Vector trong C++

Tổng quan về Iterators trong C++

Tổng quan về Iterators trong C++

Top