C++ da Switch case 'Tanlash operatori'

sherzod5048

Sherzod5048

Posted on September 29, 2022

C++ da Switch case 'Tanlash operatori'

Switch case asosan bir nechta qiymatdan, o'zgaruvchiga mos qiymatni tanlashda va qiymatga mos ravishda boshqarishni amalga oshirishda ishlatilinadi:
Switch case operatorini sintaksisi quyidagi tartibda yoziladi:
Masala 1:

Kiritgan sonimizga mos ravishda hafta kunini chiqaruvchi programma tuzilsin.

#include <iostream>

using namespace std;

int main() {
  int n;
  cin >> n;

  switch(n){
    case 1: cout << "Dushanba"; break;
    case 2: cout << "Seshanba"; break;
    case 3: cout << "Chorshanba"; break;
    case 4: cout << "Payshanba"; break;
    case 5: cout << "Juma"; break;
    case 6: cout << "Shanba"; break;
    case 7: cout << "Yakshanba"; break;
    default: cout << "Bunday hafta kuni yuq";
  }
  return 0;
}
Enter fullscreen mode Exit fullscreen mode
1
Dushanba
Enter fullscreen mode Exit fullscreen mode

Biz kiritgan son(n) case dagi qiymatga (1) tengligi uchun case 1: da berilgan ma'lumotni consolega chiqardi.

💖 💪 🙅 🚩
sherzod5048
Sherzod5048

Posted on September 29, 2022

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related