DEV Community

islomAli99
islomAli99

Posted on

Input/Output Amallari

Foydalanuvchi bilan muloqot qilish uchun dasturda kirish (input) va chiqish (output) amallaridan foydalanamiz. Bu yordamida foydalanuvchi dasturga ma'lumot kiritishi va natijani ko'rishi mumkin.

C++ da:

  • Input: cin yordamida foydalanuvchidan ma'lumot olish.

  • Output: cout yordamida natijani ekranga chiqarish.

#include <iostream>

using namespace std;

int main() 
{
    int yosh;

    cout << "Yoshingizni kiriting: ";
    cin >> yosh;

    cout << "Sizning yoshingiz: " << yosh << endl;

    return 0;
}

Enter fullscreen mode Exit fullscreen mode

Bu dastur foydalanuvchidan yoshini so'raydi va kiritilgan yoshni ekranga chiqaradi.

C# da:

  • Input: Console.ReadLine() yordamida foydalanuvchidan ma'lumot olish.

  • Output: Console.WriteLine() yordamida natijani ekranga chiqarish.

using System;

class Program 
{
    static void Main() 
    {
        Console.Write("Yoshingizni kiriting: ");
        string yosh = Console.ReadLine();
        Console.WriteLine("Sizning yoshingiz: " + yosh);
    }
}

Enter fullscreen mode Exit fullscreen mode

Bu C# dasturi ham foydalanuvchidan yoshini so'raydi va kiritilgan yoshni ekranga chiqaradi.

  1. O'zgaruvchilarning Ahmiyati
  • O'zgaruvchilarni nomlash: O'zgaruvchilarni nomlashda mantiqiy va maqsadga muvofiq nom tanlash muhim. Masalan, a yoki b kabi nomlar o'rniga yosh yoki oylik kabi tushunarli nomlar tanlash kerak.

  • O'zgaruvchilardan foydalanish: Dastur davomida o'zgaruvchilarni qo'llash orqali hisoblashlarni amalga oshirish, ma'lumotni saqlash va qayta ishlash mumkin.

  1. Matematik Amallar O'zgaruvchilar yordamida turli matematik amallarni bajarish mumkin:
  • Qo'shish (+), ayirish (-), ko'paytirish (*), bo'lish (/), qoldiq olish (%).

Misollar:

  • C++ da:
int a = 10;
int b = 5;
int yigindi = a + b; // 15
int farq = a - b;    // 5
int kopaytma = a * b; // 50
int bolinma = a / b;  // 2
int qoldiq = a % b;   // 0

Enter fullscreen mode Exit fullscreen mode
  • C# da:
int a = 10;
int b = 5;
int yigindi = a + b; // 15
int farq = a - b;    // 5
int kopaytma = a * b; // 50
int bolinma = a / b;  // 2
int qoldiq = a % b;   // 0

Enter fullscreen mode Exit fullscreen mode

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)

The Most Contextual AI Development Assistant

Pieces.app image

Our centralized storage agent works on-device, unifying various developer tools to proactively capture and enrich useful materials, streamline collaboration, and solve complex problems through a contextual understanding of your unique workflow.

👥 Ideal for solo developers, teams, and cross-company projects

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay