78
79
80
/*80. Bir hafta davomidagi kundalik temperatura berilgan bo’lsa,
hafta uchun o’rtacha temperaturani hisoblash dasturini
massivdan foydalanib tuzing.*/
#include using namespace std;
int main(){
float c=0;
//Hafta bo'lgani uchun massiv soni 7ta bo'ladi.
for(int i=0; i<7; i++){
cin>>a[i];
}
for(int i=0; i c += a[i];
}
cout<}
Navbatda oxirgi elementga teng barcha elementlar o‘chirilsin.
#include
#include #include #include #include using namespace std;
void urolov(queue &st, int n)
{
int m=st.back();
bool a=true;
while(!st.empty()){
int b=st.front();
st.pop();
if(b!=m){
cout< else{ } }
cout<int main()
{
int n;
cout<<"Navbat elementlari soni qancha: ";
cin>>n;
int x[n];
queue st;
cout< for(int i=0; i cin>>x[i];
st.push(x[i]);
}
cout< urolov(st,n);
return 0;
}
109
110
111
/*111. Bir oy davomidagi kundalik temperatura berilgan bo’lsa,
oy uchun o’rtacha temperaturani hisoblash dasturini
massivdan foydalanib tuzing..*/
#include using namespace std;
int main(){
float c=0;
int n;
cin>>n; //Oy kunlari kiritiladi.
int a[n];
for(int i=0; i cin>>a[i];
}
for(int i=0; i c += a[i];
}
cout<}
112
113
114
/*114. Bir o’lchamli massivning 10 ta elementlari ichidan
musbatlarining soni va summasini hisoblash dasturini tuzing. */
#include using namespace std;
int main(){
int n, sum, son;
cin>>n;
int a[n];
for(int i=0; i cin>>a[i];
}
for(int i=0; i if(a[i]>0){
sum += a[i];
son ++;
}
}
cout<<"Musbat elementlari summasi: "< cout<<"Musbat elementlari soni: "<}
115
/*115. 10 ta elementdan iborat massivning eng katta,
eng kichik elementlarini va ularning o’rta qiymatini
hisoblash dasturini tuzing. */
#include using namespace std;
int main() {
int m, o;
int a[10];
for(int i=0; i<10; i++) {
cin>>a[i];
}
for(int i=0; i<10; i++) {
for(int j=i+1; j<10; j++) {
if(a[i] swap(a[i],a[j]);
}
}
}
cout<<"Massivdagi Max element: "< cout<<"Massivdagi Min element: "< cout<<"Massivdagi Max va Min elementlari o'rta qiymati: "<<(a[0]+a[9])/2;
}
116
/*116. Bazaviy toifasi haqiqiy bo’lgan 10 ta elementli
A massivi berilgan. Juft indeksli elementlardan alohida,
toq indeksli elementlardan alohida massiv hosil qilish
dasturini tuzing. */
#include using namespace std;
int main(){
int t=0,y=1;
int a[10], b[5],c[5];
for(int i=0; i<10; i++){
cin>>a[i];
}
for(int i=0; i<5; i++){
b[i] = a[t];
t+=2;
}
for(int i=0; i<5; i++){
c[i] = a[y];
y+=2;
}
cout<<"Xosil bo'lgan 1 - massiv"<<"\n";
for(int i=0; i<5; i++){
cout< }
cout<<"\nXosil bolgan 2 - massiv"<<"\n";
for(int i=0; i<5; i++){
cout< }
}
117
/*117. A va B massivlari berilgan. Yangi C massivini
quyidagicha hosil qiling: A massivining elementlari
yangi massivning juft indekslari, B massivining elementlari
esa yangi massivning toq indekslarini tashkil etsin. */
#include using namespace std;
int main() {
int c, d, e, f, m=0, n=0;
cin>>c>>d;
int a[c], b[d], g[c+d];
for(int i=0; i cin>>a[i];
}
for(int i=0; i cin>>b[i];
}
for(int i=0; i<(c+d); i+=2) {
g[i] = a[m];
m ++;
}
for(int j=1; j<(c+d); j+=2) {
g[j] = b[n];
n ++;
}
for(int i=0; i<(c+d); i++) {
cout< }
}
118
/*118. Xaqiqiy toifali A va B matritsalari berilgan.
Quyidagi formula orqali yangi C matritsasini hosil
qilish dasturini tuzing: Cij = Aij + Bij; bu erda
i=1,3; j=1,2 */
#include using namespace std;
int main() {
int n;
cout<<"Kvadrat matritsa o'lchamini kiriting: (nxn)\n";
cin>>n>>n;
cout<<"A matritsani kiriting:\n";
float a[n][n], b[n][n],c[n][n];
for(int i=0; i for(int j=0; j cin>>a[i][j];
}
}
cout<<"B matritsani kiriting:\n";
for(int i=0; i for(int j=0; j cin>>b[i][j];
}
}
for(int i=0; i for(int j=0; j c[i][j] = a[i][j] + b[i][j];
}
}
cout<<"Xosil bo'lgan C matritsa:\n";
for(int i=0; i for(int j=0; j cout< }
cout<<"\n";
}
}
119
120
121
122
123
/*123. Bir o’lchovli 10 ta elementdan iborat xaqiqiy
toifali massiv elementlarini o’sib borish tartibida
saralash dasturini tuzing. */
#include using namespace std;
int main(){
int a[10];
for(int i=0; i<10; i++){
cin>>a[i];
}
for(int i=0; i<10; i++){
for(int j=i+1; j<10; j++){
if(a[i]>a[j]) swap(a[i],a[j]);
}
}
for(int i=0; i<10; i++){
cout< }
}
124
/*124. Bir o’lchovli 10 ta elementdan iborat xaqiqiy
toifali massiv elementlarini kamayib borish tartibida
saralash dasturini tuzing. */
#include using namespace std;
int main(){
int a[10];
for(int i=0; i<10; i++){
cin>>a[i];
}
for(int i=0; i<10; i++){
for(int j=i+1; j<10; j++){
if(a[i] }
}
for(int i=0; i<10; i++){
cout< }
}
125
126
126.Talaba sinfini yarating. Unda kamida 5 ta maydon va ularni ekranga chiqaruvchi, qayta ishlovchi usullarni yarating.
#include using namespace std;
class talaba
{
public:
string nomi;
string familya;
int yili;
string guruhi;
string xulqi;
void input(){
cout << "talaba nomi: "; cin >> this->nomi;
cout << "talaba familyasi: "; cin >> this->familya;
cout << "Yili: "; cin >> this->yili;
cout << "guruhi : "; cin >> this->guruhi;
cout << "qulqi: "; cin >> this->xulqi;
}
void output(){
cout << "Talaba nomi:" << this->nomi << '\n';
cout << "Talaba familyasi " << this->familya << '\n';
cout << "Talaba yili: " << this->yili << '\n';
cout << "guruhi : " << this->guruhi<< '\n';
cout << "qulqi: " << this->xulqi <<'\n';
}
};
int main(){
int n;
cout << "Nechta talaba maluloti kiritamiz ?";
cin >> n;
talaba a[n];
for(int i=0;i cout << i+1 <<"-talaba ma'lumotlarini kiriting: \n";
a[i].input();
}
cout <<"2003-yilda chiqarilgan tovarlar ro'yxati:\n";
for(int i=0;i if(a[i].yili==2003){
a[i].output();
}
}
}
127
127.Avtomashina sinfini yarating. Unda kamida 5 ta maydon va ularni ekranga chiqaruvchi, qayta ishlovchi usullarni yarating.
143
143.Fleshka va disk class larini yarating va ularni bog‘lovchi funksiyalar yarating.
#include using namespace std;
class fleshka {
public:
int ulchami;
int narxi;
void input() {
cout << "fleshka ulchami: ";
cin >> this->ulchami;
cout << "fleshka narxi: ";
cin >> this->narxi;
}
void output() {
cout << "fleshka ulchami: " << this->ulchami << '\n';
cout << "fleshka narxi: " << this->narxi << '\n';
}
};
class disk {
public:
string ulchami1;
int narxi1;
void input1() {
cout << "disk ulchami: ";
cin >> this->ulchami1; ;
cout << "disk narxi: ";
cin >> this->narxi1;
}
void output1() {
cout << "disk ulchami: " << this->ulchami1 << '\n';
cout << "disk narxi: " << this->narxi1 << '\n';
}
};
int main() {
int n;
cout << "Nechta disk kiritamiz ?";
cin >> n;
disk a[n];
for(int i=0; i cout << i+1 <<"-disk ma'lumotlarini kiriting: \n";
a[i].input1();
}
int b;
cout << "Nechta fleshka kiritamiz ?";
cin >>b ;
fleshka c[b];
for(int i=0; i cout << i+1 <<"-fleshka ma'lumotlarini kiriting: \n";
c[i].input();
}
cout <<"narxi teng bulgan fleshka va disklar \n";
for(int i=0; i for(int j=0; j if(a[i].narxi1==c[j].narxi) {
a[i].output1();
cout<<"\n";
c[j].output();
cout<<"\n";
}
}
}
}
144
144.Vector elementlarini max va min elementlarini o‘chiruvchi funksiyalar yarating.
#include using namespace std;
int main() {
int n,temp,max,min;
cin>>n;
vectorvec;
vectorvec2;
for(int i=0; i cin>>temp;
vec.push_back(temp);
}
max= *max_element(vec.begin(), vec.end());
min= *min_element(vec.begin(), vec.end());
for(int i=0; i if(min==vec.at(i)||max==vec.at(i)){i++;}
else{ vec2.push_back(vec[i]); }}
for(int i=0; i-----------------------------------------------------------------------------------------------------------
145
145.Vectorni eng katta elementidan keyingi elementlarini chiqaruvchi va o‘chiruvchi funksiyalar yarating
#include using namespace std;
int main() {
int n,temp,index;
cin>>n;
vectorvec;
for(int i=0; i cin>>temp;
vec.push_back(temp);
}
temp= *max_element(vec.begin(), vec.end());
for(int i=0; i if(temp==vec.at(i)){
index=i;
}
}
for(int i=index; i cout< }
for(int i=index; indexvec.pop_back();}
}
146
147
147.Berilgan vektordagi har xil elementlar soni topilsin.
#include using namespace std;
int main() {
int n,temp;
cin>>n;
vectorvec;
setmyset;
for(int i=0; i cin>>temp;
vec.push_back(temp);
myset.insert(temp);
}
cout<<( myset.size());
}
148
148.Ikkita bir xil elementga ega bo`lgan N o`lchamli butun tipli massiv berilgan. Bir xil elementlar nomeri topilib o`sish tartibida chiqarilsin.
#include using namespace std;
int main() {
int n;
cin>>n;
int a[n];
for(int i=0; i cin>>a[i];
}
cout<<"to`liq massiv elementlari \n";
for(int i=0 ; i cout< }
for(int i=0 ; i for(int j=i+1 ; j if(a[i]==a[j]){
cout<<"\nbir xil elementlaring indekisi "< }
}
}
149
149. N o`lchamli butun tipli massiv berilgan, hamma elementlari(o`sish yoki kamayish bo`yicha) tartiblangan. Faqat toq nomerdagi elementlari ekranga chiqarilsin,
#include using namespace std;
int main() {
int n;
cin>>n;
int a[n];
for(int i=0; i cin>>a[i];
}
sort(a,a+n);
cout<<"to`liq massiv elementlari \n";
for(int i=0 ; i cout< }
cout<<"\n toq urindagi massiv elementlari \n";
for(int i=1 ; i cout< }
}
----------------------------------------------------------------------------------------------
150. N ta tasodifiy sonlardan iborat vector hosil qiling, elementlarini kamayish tartibida saralang.
#include
using namespace std;
int main() {
int n,a;
cin>>n;
vectorvec;
srand(time(0));
for(int i=0; i a = rand()%10000;
vec.push_back(a);
}
sort(vec.begin(),vec.end());
for(int i=0 ; i cout<}
}