Bog'liq Nazariy qism(1-90) Massivlarni saralash algoritmlari
147. a, b, c uchta haqiqiy sonlar berilgan. Hech bo’lmaganda bitta juftlikning o’zaro teng sonlar ekanligini aniqlash dasturini tuzing. #include //147-masala @TBCLbot
using namespace std;
int main()
{
int a,b,c;
cin>>a>>b>>c;
cout<<"n=";cin>>n;
if(a==b || b==c || c==a)
{
if(a==b);
cout<<"a son b ga teng";
else if(b==c)
cout<<"b son c ga teng";
else
cout<<"c son a ga teng";
}
else cout<<"a,b,c sonlardan birortasi bir-biriga teng emas!";
return 0;
}
148. a, b, c tomonli uchburchakning teng yonli ekanligini aniqlang. #include //148-masala @TBCLbot
using namespace std;
int main()
{
int a,b,c;
cin>>a>>b>>c;
cout<<"n=";cin>>n;
if(a==b || b==c || c==a)
{
if(a==b&&a!=c);
cout<<"bu uchburchak teng yonli";
else if(b==c&&b!=a)
cout<<"bu uchburchak teng yonli";
else if(c==a&&b!=c)
cout<<"bu uchburchak teng yonli";
}
else cout<<"bu uchburchak teng yonli uchburchak teng emas";
return 0;
}
149. a1, a2, …, an haqiqiy sonlar ketma-ketligi berilgan. Uning [c;d] kesmada yotgan elementlarini ko’rsating. #include //149-masala @TBCLbot
using namespace std;
int main()
{
int n,c,d;
cout<<"n=";cin>>n;
int a[n];
for(int i=1;i<=n;i++)
cin>>a[i];
cout<<"c=";cin>>c;
cout<<"d=";cin>>d;
for(int i=c;i<=d;i++)
cout<return 0;
}
150. Butun sonli massivning 9 ga karrali elementlari ko’paytmasini toping. #include //150-masala @TBCLbot
using namespace std;
int main()
{
int n;
cout<<"n=";cin>>n;
int a[n];
for(int i=1;i<=n;i++)
cin>>a[i];
for(int i=1;i<=n;i++)
if(a[i]%9==0)
cout<return 0;
}
151. Berilgan N ta natural sonlardan faqat juftlarini yig’indisini topish dasturing tuzing. #include //151masala @TBCLbot
using namespace std;
int main()
{
int n,s=0;
cout<<"n=";cin>>n;
int a[n];
for(int i=1;i<=n;i++)
{
cin>>a[i];
if(a[i]%2==0)s+=a[i];
}
cout<<"s="<return 0;
}
152. Berilgan N ta natural sonlardan faqat toqlarini yig’indisini topish dasturing tuzing. #include //152-masala @TBCLbot
using namespace std;
int main()
{
int n,s=0;
cout<<"n=";cin>>n;
int a[n];
for(int i=1;i<=n;i++)
{
cin>>a[i];
if(a[i]%2!=0)s+=a[i];
}
cout<<"s="<return 0;
}
153. Ikkita sonning yig’indisini topish funksiyasini yozing va unga murojaat qiling. #include //153-masala @TBCLbot
using namespace std;
int SUMMA(int a,int b)
{
return a+b;
}
int main()
{
int a,b;
cout<<"a=";cin>>a;
cout<<"b=";cin>>b;
cout<<"a+b="<return 0;
}
154. Ikkita sonning ko’paytmasini topish funksiyasini yozing va unga murojaat qiling. #include //154-masala @TBCLbot
using namespace std;
int SUMMA(int a,int b)
{
return a*b;
}
int main()
{
int a,b;
cout<<"a=";cin>>a;
cout<<"b=";cin>>b;
cout<<"a*b="<return 0;
}
155. Ikkita sonning ayirmasini topish funksiyasini yozing va unga murojaat qiling. #include //155-masala @TBCLbot
using namespace std;
int SUMMA(int a,int b)
{
return a-b;
}
int main()
{
int a,b;
cout<<"a=";cin>>a;
cout<<"b=";cin>>b;
cout<<"a-b="<return 0;
}
156. Ikkita sonning bo’linmasini topish funksiyasini yozing va unga murojaat qiling. #include //154-masala @TBCLbot
using namespace std;
int SUMMA(int a,int b)
{
return a/b;
}
int main()
{
int a,b;
cout<<"a=";cin>>a;
cout<<"b=";cin>>b;
cout<<"a/b="<return 0;
}
157. To’g’ri to’rtburchakning tomonlari a va b berilgan. Uning yuzasini aniqlash funksiyasini yozing va unga murojaat qiling. #include //157-masala @TBCLbot
using namespace std;
int YUZA(int a,int b)
{
return a*b;
}
int main()
{
int a,b;
cout<<"a=";cin>>a;
cout<<"b=";cin>>b;
cout<<"S="<return 0;
}
158. Doiraning radiusi berilgan. Uning yuzasini aniqlash funksiyasini yozing va unga murojaat qiling. #include //158-masala @TBCLbot
using namespace std;
float YUZA(float r)
{
return r*r*M_PI;
}
int main()
{
float r;
cout<<"r=";cin>>r;
cout<<"S="<return 0;
}
159. Teng yonli trapetsiyaning a va b asoslari, balandligi berilgan. Uning yuzasini topish funksiyani yozing va unga murojaat qiling. #include //159-masala @TBCLbot
using namespace std;
int YUZA(int a,int b,float h)
{
return (a+b)*h*1./2;
}
int main()
{
int a,b;
float h;
cout<<"a=";cin>>a;
cout<<"b=";cin>>b;
cout<<"h=";cin>>h;
cout<<"S="<return 0;
}
160. Kvadratning tomoni a berilgan. Berilgan kvadratning diametrini topish funksiyasini yozing va unga murojaat qiling. #include //160-masala @TBCLbot
using namespace std;
int Radius(int a)
{
return a/2;
}
int main()
{
int a;
cout<<"a=";cin>>a;
cout<<"R="<return 0;
}
161. Berilgan satrda nechta kichik a harfi qatnashganini aniqlash dasturini tuzing. #include //161-masala @TBCLbot
using namespace std;
int main()
{
string a;
int k=0;
cout<<"Satr kiriting:";getline(cin,a);
for(int i=0;i{
if(a[i]=='a')
k++;
}
cout<<"satrdagi a harflar soni: "<return 0;
}
162. Berilgan satrda nechta kichik b harfi qatnashganini aniqlash dasturini tuzing. #include //162-masala @TBCLbot
using namespace std;
int main()
{
string a;
int k=0;
cout<<"Satr kiriting:";getline(cin,a);
for(int i=0;i{
if(a[i]=='b')
k++;
}
cout<<"satrdagi b harflar soni: "<return 0;
}
163. Berilgan satrda nechta vergul, nuqta, so’roq belgisi qatnashganini aniqlash dasturini tuzing. #include //163-masala @TBCLbot
using namespace std;
int main()
{
string a;
int k=0,k1=0,k2=0;
cout<<"Satr kiriting:";getline(cin,a);
for(int i=0;i{
if(a[i]==','||a[i]==’.’||a[i]==’?’)
k++;
}
cout<<"satrdagi vergul,nuqta,so’roqlar soni: "<return 0;
}
164. Berilgan satrda nechta raqam qatnashganini aniqlash dasturini aniqlang. #include //164-masala @TBCLbot
using namespace std;
int main()
{
string a;
int k=0;
cout<<"Satr kiriting:";getline(cin,a);
for(int i=0;i{
if(48<=a[i]&&a[i]<=57)
k++;
}
cout<<"satrdagi raqamlar soni: "<return 0;
}
165. Uchta satr berilgan. Bu satrlarni birlashtirish dasturini tuzing. #include //165-masala @TBCLbot
using namespace std;
int main()
{
string s,s1,s2,s3;
cout<<"Satr kiriting:s1=";getline(cin,s1);
cout<<"Satr kiriting:s2=";getline(cin,s2);
cout<<"Satr kiriting:s3=";getline(cin,s3);
s=s1+s2+s3;
cout<<"s1,s2,s3 satrlar birlashmasi: "<return 0;
}
166. Matn berilgan. Bu matnda “lar” qismiy satri necha marta uchrashini aniqlash dasturini tuzing. #include //166-masala @TBCLbot
using namespace std;
int main()
{
string s,s1="lar";
int k=0,m=0,n=0;
cout<<"Satr kiriting: ";getline(cin,s);
for(int i=0;i{
k=s.find(s1,i);
// cout<<"k="<if(k!=m&&k!=-1)
n++;
m=k;
}
cout<<"\nn="<return 0;
}
167. „Talaba“ strukturasini yozing va unga boshlang’ich qiymat bering. Uning 4 ta maydoni bo’lsin. #include //167-misol
using namespace std;
struct Talaba
{
string ism;
string familiya;
int kurs;
int ball;
};
int main()
{
Talaba a ={"Lazizbek","Karimov",1,5};
return 0;
}
168. „Guruh“ strukturasini yozing va unga boshlang’ich qiymat bering. Uning 4 ta maydoni bo’lsin. #include //168-masala @TBCLbot
using namespace std;
struct Guruh
{
string nom;
string shior;
string sardor;
int azo;
};
int main()
{
Guruh a ={"Yingilmas","Kuch Adolatda","Lazizbek",30};
return 0;
}
169. „Mamlakat“ strukturasini yozing va unga boshlang’ich qiymat bering. Uning 3 ta maydoni bo’lsin. {#include //169-masala @TBCLbot
using namespace std;
struct Mamlakat
string nom;
int maydon;
int aholi;
};
int main()
{
Mamlakat a ={"O'zbekiston",448921,35000000};
return 0;
}
170. „Kitob“ strukturasini yozing va unga boshlang’ich qiymat bering. Uning 3 ta maydoni bo’lsin #include //170-masala @TBCLbot
using namespace std;
struct Kitob
{
string nom;
string molif;
int sahifa;
};
int main()
{
Kitob a ={"O'tgan kunlar","Abdulla Qodiriy",620};
return 0;
}
171. Butun sonli massivning juft elementlari yig’indisini toping. #include //171masala @TBCLbot
using namespace std;
int main()
{
int n,s=0;
cout<<"n=";cin>>n;
int a[n];
for(int i=1;i<=n;i++)
{
cin>>a[i];
if(a[i]%2==0)s+=a[i];
}
cout<<"s="<return 0;
}
172. n ta butun sonlar ketma-ketligini kiriting. Hamma manfiy sonlar yig’indisini toping. #include //172-masala @TBCLbot
using namespace std;
int main()
{
int n,s=0;
cout<<"n=";cin>>n;
int a[n];
for(int i=1;i<=n;i++)
{
cin>>a[i];
if(a[i]<0)s+=a[i];
}
cout<<"s="<return 0;
}
173. n va m natural sonlar berilgan. Ularning eng kichik umumiy karralisini toping. #include //173-misol;
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;
}
174. 10 dan 40 gacha bo’lgan barcha butun sonlarning kvadratlarini chop etuvchi dastur tuzing. #include //174-masala @TBCLbot
using namespace std;
int main()
{
int n=40,s=0;
for(int i=10;i<=n;i++)
{
cout<}
return 0;
}
175. 50 dan 500 gacha bo’lgan barcha butun sonlarning kvadratlarini chop etuvchi dastur tuzing. #include //175-masala @TBCLbot
using namespace std;
int main()
{
int n=500,s=0;
for(int i=50;i<=n;i++)
{
cout<}
return 0;
}
176. 101 dan 301 gacha barcha toq sonlar yig’indisini hisoblang. #include //176-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=101,s=0;
while(k<301)
{
if(tub(k))
{
S+=k;
}
k++;
}
cout<return 0;
}
177. XOY tekislikda A nuqta o’zining koordinatalari bilan berilgan. U qayerda joylashganligini ko’rsating (qaysi o’qda yoki qaysi chorakda). #include //40-masala
//Muallif:Lazizbek Karimov
//Sana:12.01.2021
using namespace std;
int main()
{
float x,y;
cout <<" a nuqta kordinatalarini kiriting" << endl;
cout<<" x=";cin>>x;
cout<<" y=";cin>>y;
if(x==0&&y==0)cout<<"a nuqta kordinata boshida joylashgan";
else if(x==0&&y!=0)cout<<"a nuqta y o'qida joylashgan";
else if(x!=0&&y==0)cout<<"a nuqta x o'qida joylashgan";
else if(x>0&&y>0) cout<<"a nuqta birinchi chorakda joylashgan";
else if(x<0&&y>0) cout<<"a nuqta ikkinchi chorakda joylashgan";
else if(x<0&&y<0) cout<<"a nuqta uchinchi chorakda joylashgan";
else if(x>0&&y<0) cout<<"a nuqta to'rtinchi chorakda joylashgan";
return 0;
}
178. Ikkita nuqta berilgan: A(x1,y1) va B(x2, y2). Bu nuqtalardan qaysinisi koordina boshiga yaqin joylashganligini aniqlaydigan algoritm tuzing. #include #include using namespace std;
//37-masala
//Muallif:Lazizbek Karimov
//Sana:12.01.2021
int main()
{
float x1,y1,x2,y2,a,b;
cout<<"x1="; cin>>x1;
cout<<"y1="; cin>>y1;
cout<<"x2="; cin>>x2;
cout<<"y2="; cin>>y2;
a=sqrt(x1*x1+y1*y1);
b=sqrt(x2*x2+y2*y2);
if(a>b)
cout<<"A nuqta koordinata boshiga nisbattan yaqinroq joylashgan";
if(a==b)
cout<<"A nuqta ham B nuqta ham koordinata boshiga nisbattan bir xil uzoqlikda joylashgan ";
if(acout<<"B nuqta koordinata boshiga nisbatan yaqinroq joylashgan";
return 0;
}
179. Kiritilgan har bir raqam (0-9) uchun, ularga mos ingliz tilidagi nomlarini (0-zero, 1-one, 2-two...) chiqaring. #include using namespace std;
//28-masala
//Muallif:Lazizbek Karimov
//Sana:12.01.2021
int main()
{
int K;
cout<<"K=";cin>>K;
switch(K)
{
case 0:cout<<"zero";break;
case 1:cout<<"one";break;
case 2:cout<<"two";break;
case 3:cout<<"three";break;
case 4:cout<<"four";break;
case 5:cout<<"five";break;
case 6:cout<<"sex";break;
case 7:cout<<"seven";break;
case 8:cout<<"eight";break;
case 9:cout<<"nine";break;
default:cout<<"(0-9) oralig‘idagi musbat butun sonlarni kiriting!!";
}
return 0;
}