8. "(D) - bu format \"umimy\" sana:. . . . . . . .{0:D}\n" +
9. "(t) - bu format \"qisqa\" vaqt: . . . . . . . {0:t}\n" +
10. "(T) - bu format \"uzun\" vaqt:. . . . . . . . {0:T}\n" +
"(f) - Chiqish \"umumiy\"sana va \"qisqa\" vaqt: {0:f}\n" +
"(F) - Chiqish \"umumiy\"sana va \"uzun\" vaqt:. {0:F}\n" +
"(g) General - qisqa sana va qisqa vaqt: . . {0:g}\n" +
14. "(G) General - \"umumiy\" format: . . .. . . . . {0:G}\n" +
"Bo'sh format - bu, (G) formtdagidey. . . . . . {0}\n" +
"(M) - Faqat oy va sana chiqishi: . . . . . . {0:M}\n" +
"(U) Universal full date/time - bo'yicha vaqt. . {0:U}\n" +
"(Y) - ushbu format bo'yicha faqat yil chiqadi. {0:Y}\n",
DateTime::Now);
MessageBox::Show(ДатаВремя,"Vaqt va sana alohida formatlarda");
_getch(); }
Natija:
2.11- rasm. Natijalar oynasi
Konsol ilovada Visual Basic funksiyalariga murojat qilish uchun Project mеnyusidan References buyrug‘i tanlanadi, ochilgan yangi oynadan Add New Reference tugmasi bosiladi, .NET vkladkasidan Microsoft.VisualBasic. havolasi tanlanadi.
Dastur kodi quyidagicha:
#include "stdafx.h"
#include "conio.h"
using namespace System;
using namespace Microsoft::VisualBasic;
int main(array ^args){
String^ satr;
7. for (; ; ){
satr = Interaction::
InputBox("Birinchi soni kiriting:", "Ikki son", "", 100, 100);
if (Information::IsNumeric(satr) == true) break;}
Single X = Single::Parse(satr); for (; ; ){
satr = Interaction::
InputBox("Ikkinchi soni kiriting:", "Ikkita son", "", 100, 100);
if (Information::IsNumeric(satr) == true) break; }
Single Y = Single::Parse(satr);
Single Z = X + Y;
satr = String::Format("Yig'indi = {0} + {1} = {2}", X, Y, Z);
// Natijani ekranga chiqarish
Interaction::MsgBox(satr, MsgBoxStyle::Information, "Yig'indi natijasi"); _getch(); }
Natija:
2.12- rasm. MassegaBox natijalar oynasi
C++ dasturlash tili funksiyalar majmuidan iborat bo‘lganligi uchun CLR Console Application punkti orqali funksiyalarni tashkil etishda ishlatiladigan opеratorlar va ba`zi bir tushunchalarga to‘xtalib o‘tamiz.
-O‘zgaruvchilarni e`lon qilish, ularga qiymat kiritish va chiqarish opеratorlarini ishlatilishi quyidagicha bo‘ladi:
usul:
// 1-misol.cpp : main project file.
#include "stdafx.h"
#include "conio.h"
using namespace System;
int main(array ^args) {
int a, b; // o‘zgaruvchilarni e`lon qilish
// o‘zgaruvchilarga qiymat kiritish
a= Convert::ToInt32( Console::ReadLine());
b= Convert::ToInt32( Console::ReadLine());
// hisoblash
int c=a+b;
// 'S o‘zgaruvchining qiymatini chiqarish
Console::WriteLine("C= "+c); getch(); }
usul:
// 2-misol.cpp : main project file.
#include "stdafx.h"
#include "conio.h"
#include "iostream"
using namespace std;
int main(array ^> ^args) {
int a, b; // o‘zgaruvchilarni e`lon qilish
// o‘zgaruvchilarga qiymat kiritish
cin>>a; cin>>b;
// hisoblash
int c=a+b;
// C o‘zgaruvchini qiymatini chiqarish
cout<<"C= "< getch(); }
usul:
// 3-misol.cpp : main project file.
#include "stdafx.h"
#include "conio.h"
#include "stdio.h"
int main(array ^args) {
int a, b; // o‘zgaruvchilarni e`lon qilish
// o‘zgaruvchilarga qiymat kiritish
8. scanf("%d",&a);
9. scanf("%d",&b);
// hisoblash
int c=a+b;
// C o‘zgaruvchini qiymatini chiqarish
printf("C= %d",c); getch(); }
- Opеratorlarni qo‘llanilishi quyidagicha bo‘ladi:
if shart opеratorini qo‘llanilishi:
// 4-misol.cpp : main project file.
#include "stdafx.h"
#include "conio.h"
#include "iostream"
using namespace std;
int main(array ^args) {
int a, b; //o‘zgaruvchilarni e`lon qilish
cin>>a>>b;//o‘zgaruvchilarga qiymat kiritish
// if shart opеratorini qo‘llanilishi
if(a>b){cout<<"max="<
else {cout<<"max="<
Switch() tanlash opеratorini qo‘llanilishi:
// 5-misol.cpp : main project file.
#include "stdafx.h"
#include "conio.h"
using namespace System;
int main(array ^args) {
int a; // o‘zgaruvchilarni e`lon qilish
// o‘zgaruvchilarga qiymat kiritish
a= Convert::ToInt32( Console::ReadLine());
switch (a){
case 1: Console::WriteLine("Dushanba"); break;
case 2: Console::WriteLine("Seshanba"); break;
default: Console::WriteLine("Xatolik"); break;}
getch(); }
goto shartsiz o‘tish opеratorini qo‘llanilishi:
// 6-misol.cpp : main project file.
#include "stdafx.h"
Dastur natijasi: 12
a 10 dan katta
#include "conio.h"
using namespace System;
int main(array ^args) {
int a; // o‘zgaruvchilarni e`lon qilish
// o‘zgaruvchilarga qiymat kiritish
45
Oybek Mallayev
a= Convert::ToInt32( Console::ReadLine());
if(a>10){goto bir;}
Console::WriteLine("a 10 dan kichik");
bir: Console::WriteLine("a 10 dan katta");
getch(); }
while() sharti oldin tеkshiriladigan sikl opеratorini qo‘llanilishi:
// 7-misol.cpp : main project file.
#include "stdafx.h"
#include "conio.h"
using namespace System;
int main(array ^args) {
// o‘zgaruvchilarni e`lon qilish
7. int n,i=1, s=0;
// o‘zgaruvchilarga qiymat kiritish
n= Convert::ToInt32( Console::ReadLine());
while (i<=n){
Console::WriteLine(i); 12.s+=i; i++; }
Console::WriteLine("Yig'indi= "+s);
getch();}
do while() sharti kеyin tеkshiriladigan sikl opеratorini qo‘llanilishi:
// 8-misol.cpp : main project file.
#include "stdafx.h"
#include "conio.h"
using namespace System;
int main(array ^args) {
// 'o‘zgaruvchilarni e`lon qilish
7. int n,i=1, s=0;
// 'o‘zgaruvchilarga qiymat kiritish
n= Convert::ToInt32( Console::ReadLine());
do {
Console::WriteLine(i); 12.s+=i; i++; } while (i<=n);
Console::WriteLine("Yig'indi= "+s);
getch(); }
for sikl opеratorini qo‘llanilishi:
// 9-misol.cpp : main project file.
#include "stdafx.h"
#include "conio.h"
using namespace System;
int main(array ^args) {
// 'o‘zgaruvchilarni e`lon qilish
7. int n,i=1, s=0;
// 'o‘zgaruvchilarga qiymat kiritish
n= Convert::ToInt32( Console::ReadLine());
10.for(i=1;i<=n;i++){
11.Console::WriteLine(i);
12.s+=i; }
Console::WriteLine("Yig'indi= "+s);
getch();
15.}
Massiv va uning qo‘llanilishi:
// 10-misol.cpp : main project file.
#include "stdafx.h"
#include "conio.h"
using namespace System;
int main(array ^args) {
6. int n, A[]={1,-4,77,-2};
n= Convert::ToInt32( Console::ReadLine());
for(int i=0;i
3
A[0,0]=
|
1
|
A[0,1]=
|
-4
|
A[0,2]=
A[1,0]=
|
75
2
|
A[1,1]=
|
-6
|
A[1,2]=
|
9
|
A[2,0]=
A[2,1]=
|
4
8
|
A[2,2]=
|
-3
|
Console::WriteLine("A["+i+"]= "+A[i]); }
getch();
11.}
Ikki o‘lchovli massiv va uning qo‘llanilishi:
// 11-misol.cpp : main project file.
#include "stdafx.h"
#include "conio.h"
using namespace System;
int main(array ^args) {
6. int n,A[][4]={{1,-4,75},{2,-6,9},{4,8,-3}};
n= Convert::ToInt32(Console::ReadLine());
for(int i=0;i
for(int j=0;j
;
10.Console::WriteLine("A["+i+","+j+"]= "+A[i][j])
11.} } getch();
12.}
Do'stlaringiz bilan baham: |