Uchinchi dars if va else

zafar7709

zafar7709

Posted on March 12, 2024

Uchinchi dars if va else
#include <iostream>

using namespace std;

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

    if(n > 0)
    {
      cout << "1";
    }
    else
    {
       cout << "0";
    }

  return 0;
}
Enter fullscreen mode Exit fullscreen mode

if bu shart togri berilgan bolsa if ichiga nima yozgan bosiz shuni chiqardi.
else bu shart xato bsa shuni ichiga kiradi yozgan narsani chiqardi.

Bizda else if bor bu kodni namunada korsiz boladi.

#include <iostream>
using namespace std;

int main()
 {
    int son;

    cout << "Istalgan son kiriting: ";
    cin >> son;

    if (son > 0)
    {
        cout << "Bu son musbat." << endl;
    } else if (son < 0)
    {
        cout << "Bu son manfiy." << endl;
    } else 
    {
        cout << "Bu son nolga teng." << endl;
    }

    return 0;
}
Enter fullscreen mode Exit fullscreen mode

else if bu agar birinchi if ishlmasa kengisiga otadi.

💖 💪 🙅 🚩
zafar7709
zafar7709

Posted on March 12, 2024

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

Sign up to receive the latest update from our blog.

Related