Nazariy qism(1-90) Massivlarni saralash algoritmlari


A[n] massiv berilgan. Bu massivning barcha elementlari ko’paytmasini topish dasturini tuzing



Download 245,36 Kb.
bet41/44
Sana18.07.2022
Hajmi245,36 Kb.
#822954
1   ...   36   37   38   39   40   41   42   43   44
Bog'liq
Nazariy qism(1-90) Massivlarni saralash algoritmlari

95. A[n] massiv berilgan. Bu massivning barcha elementlari ko’paytmasini topish dasturini tuzing
#include
//95-misol @TBCLbot
using namespace std;

int main()


{
int n,s=1;
cout<<"massiv elementlari sonini kiriting :"<cin>>n;
int a[n];
srand(time(NULL));
for(int i=0;i{
a[i]=rand()%10;
cout<s=s*a[i];
}
cout<<"massiv elementlari yig`indisi :"<return 0;
}
96. A[n] massiv berilgan. Bu massivning uchga karrali elementlarini chop etish dasturini tuzing.
#include
//96-misol @TBCLbot
using namespace std;

int main()


{
int n,s=1;
cout<<"massiv elementlari sonini kiriting :"<cin>>n;
int a[n];
srand(time(NULL));
for(int i=0;i{
a[i]=rand()%10;
if(a[i]%3==0)
cout<}
return 0;
}
97. B[n] massiv berilgan. Bu massivning hamma manfiy elementlari nechta ekanligini aniqlash dasturini tuzing

#include


//97-misol; @TBCLbot
using namespace std;
int main()
{
int n,s=1;
cout<<"massiv elementlari sonini kiriting :"<cin>>n;
int B[n];
srand(time(NULL));
for(int i=0;i{
B[i]=rand()%10;
if(i%4==0)
B[i]*=-1;
if(B[i]<0)
cout<}

return 0;


}
98. -50 dan katta va 200 dan kichik oraliqdagi, 3 va 4 ga karrali butun sonlarning yig’indisini toping.
#include
//98-misol;@TBCLbot
using namespace std;

int main()


{
int s=0;
for(int i=-50;i<=200;i++)
{
if(i%12==0)
s+=i;
}
cout<<"3 va 4 ga karrali sonlar yig`indisi :"<return 0;
}
99. n va m natural sonlar berilgan. Ularning eng kichik umumiy karralisini toping.
#include
//99-misol; @TBCLbot
using namespace std;
int ekub(int a,int b)
{
while(b)
{
a%=b;
swap(a,b);

}
return a;


}
int main()
{
int a,b,EKUB,EKUK;
cin>>a>>b;
EKUB=ekub(a,b);
EKUK=(a*b)/EKUB;
cout<<"EKUK :="<return 0;
}
100. Natural n sonini faktorialini hisoblash uchun dastur tuzing (n sonining faktoriali 1*2*…*n ga teng bo’ladi).
#include
//100-misol; @TBCLbot
using namespace std;
int main()
{
int n,s=1;
cout<<"n="; cin>>n;
for(int i=1;i<=n;i++)
{
s=s*i;
}
cout<<"n!= "<return 0;
}
101. 101 dan 301 gacha barcha toq sonlar yig’indisini hisoblang.
#include
//101-misol; @TBCLbot
using namespace std;
int main()
{
int s=0;
for(int i=101;i<301;i=i+2)
{
s=s+i;
cout<}
cout<<"toq sonlar yig`indisi"<cout<<"101+...+301= "<return 0;
}
102. n ta butun sonlar ketma-ketligini kiriting. Hamma manfiy sonlar yig’indisini toping.
#include
//102-misol; @TBCLbot
using namespace std;
int main()
{

int a[]={0};


int n,s=0;
cout<<"n="; cin>>n;
for(int i=0;i{
cout<<"A["<cin>>a[i];
}
for(int i=0;i{
if(a[i]<0)
s+=a[i];
}
cout<<"s="<return 0;
}
103. n ta sondan eng kattasini topuvchi dasturni tuzing.
#include
//103-misol; @TBCLbot
using namespace std;

int main()


{
int n,a,k=0,max1;
cin>>n;
cin>>a;
max1=a;
for(int i=1;i{
cin>>a;
if(a>max1)max1=a;
}
cout<<"n ta son ichidagi eng kattasi: "<return 0;
}
104. Barcha uch xonali tub sonlar topilsin. Ularning barchasini va umumiy sonini chop eting.
#include
//104-misol; @TBCLbot
using namespace std;
bool tub(int k)
{
int s=0;
for(int j=1;j<=k;j++)
if(k%j==0)
s++;
if(s==2)
return 1;
else return 0;
}
int main()
{
int k=100;
while(k<999)
{
if(tub(k))
{
cout<}
k++;
}
return 0;
}

105. 100 ta birinchi tub son topilsin.
#include
//105-misol; @TBCLbot
using namespace std;
bool tub(int k)
{
int s=0;
for(int j=1;j<=k;j++)
if(k%j==0)
s++;
if(s==2)
return 1;
else return 0;
}
int main()
{
int k=1;
while(k<100)
{
if(tub(k))
{
cout<}
k++;
}
return 0;
}
106. Sonli yozuvida bir xil raqamlari bo’lmagan barcha uch xonali sonlarni o’sish tartibida chop qiling.
#include
//105-misol; @TBCLbot
using namespace std;
int main()
{
int n1,n2,n3;
for(int i=100;i<1000;i++)
{
n1=i/100;
n2=(i/10)%10;
n3=i%10;
if(n1!=n2&&n2!=n3&&n1!=n3)
cout<}
return 0;
}

107. a1, a2, a3, … , a20 butun sonlar ketma-ketligi berilgan. Ketma-ketlikning barcha elementlari o’zaro teng bo’ladimi?
#include
//107-misol; @TBCLbot
using namespace std;
int main()
{
int a[20],k=0;
for(int i=0;i<20;i++)
{
cin>>a[i];
if(a[0]==a[i])
//cout<k++;
}
if(k==20)
cout<<"ketma ket sonlar o`zaro reng";
else cout<<"teng emas";
return 0;
}
108. Berilgan matnda nechta so’z mavjudligini aniqlash dasturini tuzing.
#include
//108-misol; @TBCLbot
using namespace std;
int main()
{

char a[128] = "";

cout << "Istalgan matnni kiriting:\n";
cin.getline(a, 128);

cout <<"Satr "<
return 0;
}
109. Berilgan ikkita satrlarni birlashtirish dasturing tuzing
#include
//109-misol; @TBCLbot
using namespace std;
int main()
{

char someText1[20] = "www.";


char someText2[] = "samdu.uz";
cout << "Birinchi satr: " << someText1 <cout << "Ikkinchi satr:" << someText2 <int count1 = 0;


while (someText1[count1] != 0)
{
count1++;
}

int count2 = 0;


while (someText2[count2] != 0)
{
someText1[count1] = someText2[count2];
count1++;
count2++;
}

cout << "Birlashtirilgan satr:" << someText1 << endl;

return 0;
}
110. Berilgan satrning uzunligini va xotira hajmini aniqlang.
#include
#include
using namespace std;

int main()


{
string myString;
//110-savol; @TBCLbot
cout << "Ismingiz nima? ";
getline(cin, myString);

cout << "Satr, " << myString << "! \n";



cout << "Satr uzunligi: " << myString.size() << "\n";
cout << "Satr hajmi: " <}
111. S1 va S2 lar berilgan. Bu ikki satrning uzunliklarini taqqoslang.
#include
#include
using namespace std;
//111-savol;
int main()
{
string s1="matematika";
string s2="fizika";
if(s1.size()>s2.size())
cout<<"s1 satr s2 satrdan uzun";
else if(s2.size()>s1.size())
cout<<"s2 satr s1 satrdan uzun";
else if(s1.size()==s2.size())
cout<<"ikkita satr teng";
return 0;
}
112. a va b sonlardan eng kattasini topishni funksiya yordamida hal eting.
#include
#include
using namespace std;
//112-savol; @TBCLbot
int katta(int a,int b)
{
if(a>=b)
return a;
else return b;
}
int main()
{
int a,b;
cout<<"a="; cin>>a;
cout<<"b="; cin>>b;
cout<<"katta son " <return 0;
}
113. Tub sonlarni aniqlashga imkon beruvchi funksiyani aniqlab, barcha uch xonali tub sonlarni aniqlang.
#include
//113-misol; @TBCLbot
using namespace std;
bool tub(int k)
{
int s=0;
for(int j=1;j<=k;j++)
if(k%j==0)
s++;
if(s==2)
return 1;
else return 0;
}
int main()
{
int k=100;
while(k<999)
{
if(tub(k))
{
cout<}
k++;
}
return 0;
}
114. Ikkita uchburchakning tomonlari berilgan. Uning tomonlariga ko’ra uchburchak yuzasini va perimetrlarini hisoblash uchun funksiyani aniqlab, ularning yuzalarini va perimetrlarini yig’indisini toping.
#include
//114-misol; @TBCLbot
using namespace std;
int yuza(int a, int b,int c,float p)
{
float s;
s=sqrt((p/2)*((p/2)-a)*((p/2)-b)*((p/2)-c));
return s;
}
int perimetr(int a,int b,int c)
{
float p;
p=a+b+c;
return p;
}
int main()
{
int a,b,c,a1,b1,c1,p,s;
cout<<"1-uchburchak tomonlari"<cin>>a>>b>>c;
cout<<"2-uchburchak tomonlari"<cin>>a1>>b1>>c1;
cout<cout<
cout<cout<
return 0;
}
115. Uchburchakning perimetrini va yuzasini funksiyadan foydalanib toping.
#include
//115-misol; @TBCLbot
using namespace std;
int yuza(int a, int b,int c,float p)
{
float s;
s=sqrt((p/2)*((p/2)-a)*((p/2)-b)*((p/2)-c));
return s;
}
int perimetr(int a,int b,int c)
{
float p;
p=a+b+c;
return p;
}
int main()
{
int a,b,c,p,s;
cout<<"uchburchak tomonlari kiriting : "<cin>>a>>b>>c;
cout<cout<
return 0;
}
116. Talabalar familyasi, ismi, kursi, reyting bali haqida structura yarating. X kursdagi 4 bahoga o‘qiydigan talabalar familya va ismini aniqlang.
#include
//116-misol @TBCLbot
using namespace std;
struct Sinf
{
string ism,familiya;
int kurs,ball;
};
int main()
{
Sinf a[100];
int X,n;
cout<<"Talabalar soni:n=";cin>>n;
for(int i=1;i<=n;i++)
{
cout<>a[i].ism;
cout<<"Talaba familiyasi:";cin>>a[i].familiya;
cout<<"Talaba Kursi:";cin>>a[i].kurs;
cout<<"Talaba Reytingi:";cin>>a[i].ball;
cout<<"\n*********************************\n";
}
cout<<"\n Kursni kiriting X=";cin>>X;
for(int i=1;i<=n;i++)
{
if(a[i].kurs==X)
{
cout<cout<}
}
return 0;
}
117. Talabalar familyasi, ismi, kursi, reyting bali haqida structura yarating. X kursdagi eng a‘lochi talabani familya va ismini aniqlang.
#include
//117-misol @TBCLbot
using namespace std;
struct Sinf
{
string ism,familiya;
int kurs,ball;
};
int main()
{
Sinf a[100];
int X,n;
cout<<"Talabalar soni:n=";cin>>n;
for(int i=1;i<=n;i++)
{
cout<>a[i].ism;
cout<<"Talaba familiyasi:";cin>>a[i].familiya;
cout<<"Talaba Kursi:";cin>>a[i].kurs;
cout<<"Talaba Reytingi:";cin>>a[i].ball;
cout<<"\n*********************************\n";
}
cout<<"\n Kursni kiriting X=";cin>>X;
int k=0,m=0;
for(int i=1;i<=n;i++)
{
if(a[i].kurs==X)
{
if(a[i].ball>m)
{
m=a[i].ball;
k=i;
}}
}
cout<cout<return 0;
}
118. Uchta uchburchak tomonlari bilan berilgan. Bu uchburchaklarning eng katta yuzaga ega bo’lganini nomerini toping.
#include
//118-masala @TBCLbot
using namespace std;
float Yuza(float a,float b,float c)
{
float s,p;
p=(a+b+c)*1./2;
s=sqrt(p*(p-a)*(p-b)*(p-c));
return s;
}
int main()
{
float a1,b,c;
float a[3];
for(int i=1;i<=3;i++)
{
cout<>a1>>b>>c;
a[i]=Yuza(a1,b,c);
}
int m=a[1],i;
for(i=1;i<=3;i++)
if(mfor(i=1;i<=3;i++)
{
if(a[i]==m)
{
cout<<"Eng katta yuzaga ega bo’lgan uchburchak nomeri: "<}
}
return 0;
}
119. Aylanalar radiuslari bilan berilgan. Qaysi aylanadan eng katta yuzali doira kesib olish mumkin.
#include
//119-masala @TBCLbot
using namespace std;
float Yuza(float r)
{
return M_PI*r*r;
}
int main()
{
float r;
float a[3];
for(int i=1;i<=3;i++)
{
cout<>r;
a[i]=Yuza(r);
}
int m=a[1];
for(int i=1;i<=3;i++)
if(mfor(int i=1;i<=3;i++)
{
if(a[i]==m)
{
cout<<"eng katta yuzali doira nomeri: "<break;
}
}
return 0;
}
120. N ta natural sonning EKUBini aniqlang.
#include
//120-misol @TBCLbot
using namespace std;

int ekub(int a,int b)


{
while(b)
{
a%=b;
swap(a,b);}
return a;
}
int main()
{
int n;
cout<<"n="; cin>>n;
int a,b,i=1;
cout<<" "; cin>>a;
while(i{
cout<<" ";cin>>b;
a=ekub(a,b);
i++;
}
cout <<"kiritilgan n ta sonnig EKUB :"<return 0;
}
121. [N;M] oralig’ida joylashgan tub sonlardan massiv hosil qiling.
#include
//121-masala @TBCLbot
using namespace std;
bool tub(int k)
{
int s=0;
for(int j=1;j<=k;j++)
if(k%j==0)
s++;
if(s==2)
return 1;
else return 0;
}
int main()
{
int k,m,n;
cout<<"n=";cin>>n;
cout<<"m=";cin>>m;
k=n;
while(k<=m)
{
if(tub(k))
{
cout<}
k++;
}
return 0;
}
122. EKUB(a,b,c) ni aniqlang.
#include
//122-misol @TBCLbot
using namespace std;

int ekub(int a,int b,int c)


{
while(b)
{
a%=b;
swap(a,b);}
while(a)
{
c%=a;
swap(a,c);}
return c;
}
int main()
{
int a,b,c,k;
cout<<"a="; cin>>a;
cout<<"b="; cin>>b;
cout<<"c="; cin>>c;
k=ekub(a,b,c);
cout <<"EKUB(a,b,c) :"<return 0;
}

Download 245,36 Kb.

Do'stlaringiz bilan baham:
1   ...   36   37   38   39   40   41   42   43   44




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

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish