9.
cin>>a; cin>>b;
10.
// hisoblash
11.
int c=a+b;
12.
// C o‘zgaruvchini qiymatini chiqarish
13.
cout<<"C= "<
}
3- usul:
1.
// 3-misol.cpp : main project file.
Dastur natijasi:
12
4
C=16
Dastur natijasi:
12
4
С=16
46
Oybek Mallayev
8.
a= Convert::ToInt32( Console::ReadLine());
9.
if(a>10){goto bir;}
10.
Console::WriteLine("a 10 dan kichik");
11.
bir: Console::WriteLine("a 10 dan katta");
12.
getch(); }
4- while() sharti oldin tеkshiriladigan sikl opеratorini qo‘llanilishi:
1.
// 7-misol.cpp : main project file.
2.
#include "stdafx.h"
3.
#include "conio.h"
4.
using namespace System;
5.
int main(array ^args) {
6.
// o‘zgaruvchilarni e`lon qilish
7.
int n,i=1, s=0;
8.
// o‘zgaruvchilarga qiymat kiritish
9.
n= Convert::ToInt32( Console::ReadLine());
10.
while (i<=n){
11.
Console::WriteLine(i);
12.
s+=i; i++; }
13.
Console::WriteLine("Yig'indi= "+s);
14.
getch();}
5- do while() sharti kеyin tеkshiriladigan sikl opеratorini qo‘llanilishi:
1.
// 8-misol.cpp : main project file.
2.
#include "stdafx.h"
3.
#include "conio.h"
4.
using namespace System;
5.
int main(array ^args) {
6.
// 'o‘zgaruvchilarni e`lon qilish
7.
int n,i=1, s=0;
8.
// 'o‘zgaruvchilarga qiymat kiritish
9.
n= Convert::ToInt32( Console::ReadLine());
10.
do {
11.
Console::WriteLine(i);
12.
s+=i; i++; } while (i<=n);
13.
Console::WriteLine("Yig'indi= "+s);
14.
getch(); }
6- for sikl opеratorini qo‘llanilishi:
1.
// 9-misol.cpp : main project file.
2.
#include "stdafx.h"
3.
#include "conio.h"
4.
using namespace System;
5.
int main(array ^args) {
6.
// 'o‘zgaruvchilarni e`lon qilish
7.
int n,i=1, s=0;
8.
// 'o‘zgaruvchilarga qiymat kiritish
9.
n= Convert::ToInt32( Console::ReadLine());
10.
for(i=1;i<=n;i++){
11.
Console::WriteLine(i);
Dastur natijasi:
4
1
2
3
4
Yig’indi= 10
Dastur natijasi:
4
1
2
3
4
Yig’indi= 10
Dastur natijasi:
4
1
2
3
4
Yig’indi= 10
47
Oybek Mallayev
12.
s+=i; }
13.
Console::WriteLine("Yig'indi= "+s);
14.
getch();
15.
}
7- Massiv va uning qo‘llanilishi:
1.
// 10-misol.cpp : main project file.
2.
#include "stdafx.h"
3.
#include "conio.h"
4.
using namespace System;
5.
int main(array ^args) {
6.
int n, A[]={1,-4,77,-2};
7.
n= Convert::ToInt32( Console::ReadLine());
8.
for(int i=0;i
9.
Console::WriteLine("A["+i+"]= "+A[i]); }
10.
getch();
11.
}
8- Ikki o‘lchovli massiv va uning qo‘llanilishi:
1.
// 11-misol.cpp : main project file.
2.
#include "stdafx.h"
3.
#include "conio.h"
4.
using namespace System;
5.
int main(array ^args) {
6.
int n,A[][4]={{1,-4,75},{2,-6,9},{4,8,-3}};
7.
n= Convert::ToInt32(Console::ReadLine());
8.
for(int i=0;i
9.
for(int j=0;j
10.
Console::WriteLine("A["+i+","+j+"]= "+A[i][j]);
11.
} } getch();
12.
}
9- void turidagi funksiya va uning qo‘llanilishi:
1.
// 12-misol.cpp : main project file.
2.
#include "stdafx.h"
3.
#include "conio.h"
4.
using namespace System;
5.
void mas_in(int *A, int n){
6.
for(int i=0;i
7.
A[i]=Convert::ToInt32(
8.
Console::ReadLine());} }
9.
void mas_out(int *A, int n){
10.
for(int i=0;i
11.
Console::WriteLine("A["+i+"]= "+A[i]);} }
12.
int main(array ^args)
13.
{ int n,*A = new int[100];
14.
n= Convert::ToInt32( Console::ReadLine());
15.
mas_in(A,n);
16.
mas_out(A,n); getch(); }
Dastur natijasi:
4
1
-4
77
-2
3
A[0,0]= 1
A[0,1]= -4
A[0,2]= 75
A[1,0]= 2
A[1,1]= -6
A[1,2]= 9
A[2,0]= 4
A[2,1]= 8
A[2,2]= -3
3
1
2
3
A[0]= 1
A[1]= 2
A[2]= 3
48
Oybek Mallayev
10- funksiya va uning qo‘llanilishi:
1.
// 13-misol.cpp : main project file.
2.
#include "stdafx.h"
3.
#include "conio.h"
4.
using namespace System; int s;
5.
float mas_sum(int *A, int n){
6.
for(int i=0;i
7.
s+=A[i];} return s; }
8.
void mas_in(int *A, int n){
9.
for(int i=0;i
10.
A[i]=Convert::ToInt32(
11.
Console::ReadLine());} }
12.
int main(array ^args) {
13.
int n,*A = new int[100];
14.
n= Convert::ToInt32( Console::ReadLine());
15.
mas_in(A,n);
16.
Console::WriteLine("Summa= "+mas_sum(A,n));
17.
getch();
18.
}
11- Fayllar bilan ishlovchi maxsus funksiyalar va uning qo‘llanilishi:
1.
// 14-misol.cpp: matinli fayldan o’qish.
2.
#include "stdafx.h"
3.
#include "conio.h"
4.
#include "iostream"
5.
#include
6.
using namespace std;
7.
int main(array ^args){
8.
FILE * fayl; int a=2; float b=4.5; char satr[20];
9.
fayl=fopen("1.txt","r");// faylni o'qish uchun ochish
10.
if(fayl==NULL){cout<<"Fayl topilmadi"<
11.
fscanf(fayl," %d",&a); cout<<"a= "<
12.
fscanf(fayl," %f",&b); cout<<"b= "<
13.
fscanf(fayl,"%s",satr); cout<<"satr= "<
14.
_getch();}
11- Struktura(struct{}) va uning qo‘llanilishi:
1.
// 14-misol.cpp : main project file.
2.
#include "stdafx.h"
3.
#include "conio.h"
4.
#include "iostream"
5.
using namespace std; int s;
6.
struct talaba
7.
{ char ism[20];
8.
char fam[20];
9.
int yosh;
10.
float stipendiya; };
Do'stlaringiz bilan baham: |