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;
}
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;
}
Do'stlaringiz bilan baham: