Sherzod5048
Posted on September 29, 2022
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;
}
1
Dushanba
Biz kiritgan son(n) case dagi qiymatga (1) tengligi uchun case 1: da berilgan ma'lumotni consolega chiqardi.
💖 💪 🙅 🚩
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.