DEV Community

Sherzod5048
Sherzod5048

Posted on

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.

Sentry image

Hands-on debugging session: instrument, monitor, and fix

Join Lazar for a hands-on session where you’ll build it, break it, debug it, and fix it. You’ll set up Sentry, track errors, use Session Replay and Tracing, and leverage some good ol’ AI to find and fix issues fast.

RSVP here →

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs