Sharof rashidov nomidagi samarqand davlat universiteti dasturlash asoslari


struct complex alfa = {1.2, -4.5}, betta = {5.6, -7.8), sigma


Download 0.53 Mb.
bet2/5
Sana13.04.2023
Hajmi0.53 Mb.
#1355114
1   2   3   4   5
Bog'liq
Tursunov Aziz (Dasturlash asoslari fanidan mustaqil ish)

struct complex alfa = {1.2, -4.5}, betta = {5.6, -7.8), sigma;
  • sigma.real = alfa.real + betta.real;
  • sigma.imag = alfa.imag + betta.imag;
  • Aniq strukturalar elementlari dasturda alohida kiritilishi va chiqarilishi zarur. Quyidagi misolda xizmatchi strukturasi kiritiladi:
    • #include
    • struct employee
    • {
    • char name [64];
    • long employee_id;
    • float salary;
    • char phone[10];
    • int office_number;
    • } worker;
    • void show_employee(employee worker)
    • {
    • printf("Ismi: %s", worker.name);
    • printf("\nTelefon: %s",worker.phone);
    • printf("\nNomer: %ld",worker.employee_id);
    • printf("\nOylik: %f",worker.salary);
    • printf("\nOfis: %d",worker.office_number);
    • };
    • int main()
    • {
    • worker.employee_id = 12345;
    • worker.salary = 25000.00;
    • worker.office_number = 102;
    • printf("\n ismi:");
    • scanf("%s",&worker.name);
    • printf("\n telefon:");
    • scanf("%s",&worker.phone);
    • show_employee(worker);
    • return 0;
    • }
    • Birlashmalar
    • Strukturalarga yaqin tushuncha bu birlashma tushunchasidir. Birlashmalar union xizmatchi so’zi yordamida kiritiladi. Misol uchun:
    • union
    • {
    • long h;
    • int i,j;
    • char c[4]
    • }UNI;
    • Birlashmalarning asosiy xususiyati shundaki, uning hamma elementlari bir xil boshlang’ich adresga ega bo’ladi.
    • Birlashmalarning asosiy afzalliklaridan biri xotira biror qismi qiymatini har xil tipdagi qiymat shaklida qarash mumkin.
    • union
    • {
    • float f;
    • unsigned long k;
    • char h[4];
    • }fl;
    1   2   3   4   5




    Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
    ma'muriyatiga murojaat qiling