19
|
VECTOR hosil qiling va uning mukammal son bo’lgan i elementlarini ko’paytmasini toping
(mukammal son deb bo’luvchilari yig’indisi(o’zidan tashqari) o’ziga teng bo’lgan songa aytiladi.
Masalan 6=1+2+3 ;
|
#include
#include
#include
using namespace std;
sumdiv(int num, int x)
{
if(x==1)
return 1;
if(num%x==0)
return x + sumdiv(num,x-1);
else
return sumdiv(num,x-1);
}
int main() {
cout<<"Vectorlarning o'lchamini kiriting n=";
int n;
cin>>n;
vector veca(n);
cout<<"\nBirinchi vectorning elementlarini kiriting: \n";
for (int i=0; i
cin>>veca[i];
}
int p=1;
for (int i=0; i
int a = veca[i];
if(sumdiv(a, a/2) == a){
p*=a;
}
}
cout<<"\n berilgan vectorning mukammal sonlari ko'paymasi: "<
}
15
|
Dekning toq elementlaridan navbat, juft elementlaridan stek hosil qiling.
|
#include
#include
#include
#include
#include
using namespace std;
void PrintStack(stack s)
{
if (s.empty())
return;
int x = s.top();
s.pop();
PrintStack(s);
cout << x << " ";
s.push(x);
}
int main()
{
deque mydeque{ 1, 2, 3, 4, 5, 6, 7, 8, 9};
stack mystack;
queue myqueue;
cout<<"Berilgan deque: ";
for (auto i = mydeque.begin(); i != mydeque.end(); ++i) {
cout<<*i<<" ";
}
for (auto i = mydeque.begin(); i != mydeque.end(); ++i) {
if (*i % 2 == 0) {
mystack.push(*i);
} else {
myqueue.push(*i);
}
}
cout<<"\nStack: ";
PrintStack(mystack);
cout<<"\nQueue : ";
while(!myqueue.empty()){
cout<<" "<
myqueue.pop();
}
return 0;
}
Berilgan string turidagi to’plamning juft uzinlikka ega bo’lgan elementidan 2- to’plamni, toq uzinlikdagi elementidan 3- to’plamni hosil qiluvchi va ularni ekranga chiqaruvchi dastur tuzing. Ikkala to’plamdan ham bir xil qiymatli elemetlar o’chirilib Saralangan to’plam hosil qilinsin hamda uning qiymatlari ekranga chiqarilsin.
#include
#include
using namespace std;
int main()
{string str; int k=0;
set str1;
set ::iterator itr;
set str2;
set str3;
ifstream infile("text.txt");
string line;
while (getline(infile, line))
{
istringstream iss(line);
string a;
if (!(iss >> a)) { break; }
str1.insert(a);
k++;
}
cout<<"\n---------------Berilgan string turidagi so'zlar'---------------\n";
int f;
for (int i=0; i
{itr=str1.begin(); str=*itr; cout<
str1.erase(itr);
f=str.length();
if (f%2==0){
str2.insert(str);
} else {
str3.insert(str);
}
}
cout<<"\n\n----------Juft uzunlikdagi so'zlar -----------\n";
int i=1;
for(itr=str2.begin(); itr!=str2.end(); ++itr){
cout<
}
cout<<"\n\n----------Toq uzunlikdagi so'zlar -----------\n";
int j=1;
for(itr=str3.begin(); itr!=str3.end(); ++itr){
cout<
}
}
Operatsion tizimlar haqida (nomi, yili, razryadlar soni, turi va imkoniyatlarining soni) to’plam berilgan. Opetarsion tizimlarni nomi, yili, razryadlar soni, turi va imkoniyatlarining soni bo’yicha qidiruvchi hamda topilgan natijani faylga saqlashni taklif qiladigan dastur tuzing.
#include
using namespace std;
class komp {
public:
string nomi;
int yili;
int rzr_soni;
string turi;
int imk_soni;
void komp1( int xs, int ts, string qs, int bs){
this->yili = xs;
this->rzr_soni = ts;
this->turi = qs;
this->imk_soni = bs;
}
void show(){
cout<
}
};
int main()
{
komp k[10];
map mp;
ifstream infile("OP.txt");
int z=0;
string line;
while (getline(infile, line))
{
istringstream iss(line);
if (!(iss >> k[z].nomi >> k[z].yili>>k[z].rzr_soni>>k[z].turi>>k[z].imk_soni)) { break; }
z++;
}
for(int i=0; i
mp[i+1] = k[i];
}
map::iterator it = mp.begin();
cout<<"--------------------Berilgan OPlar ro'yhat----------------------\n\n";
cout<<"OP nomi | OP yili | OP razryad soni | OP turi | OP imkoniyatlari soni | \n";
cout<<"-----------------------------------------------------------------------------------------\n";
while (it != mp.end())
{
int word = it->first;
komp a = it->second;
a.show();
it++;
}
string a1,d;
int c,b,e;
cout<<"\nqidirilayotgan OP nomi: "; cin>>a1;
cout<<"qidirilayotgan OP yili: "; cin>>b;
cout<<"qidirilayotgan OP razryad soni: "; cin>>c;
cout<<"qidirilayotgan OP turi: "; cin>>d;
cout<<"qidirilayotgan OP imkoniyatlar soni: "; cin>>e;
map::iterator it1 = mp.begin();
cout<<"--------------------Topilgan OPlar ro'yhat----------------------\n\n";
cout<<"OP nomi | OP yili | OP razryad soni | OP turi | OP imkoniyatlari soni | \n";
cout<<"-----------------------------------------------------------------------------------------\n";
while (it1 != mp.end())
{
int word = it1->first;
komp a = it1->second;
if(a.nomi==a1 || a.yili==b || a.rzr_soni==c || a.turi==d || a.imk_soni==e){
a.show();
}
it1++;
}
cout<<"\n\n__________________________________________________________\n";
cout<<"topilgan malumotlarni Faylga saqlaysizmi(1(yes)/0(no)): ";
int p1;
cin>>p1;
switch(p1){
case 1: {
ofstream yoz("OPlar.txt",ios::app);
map::iterator it2 = mp.begin();
yoz<<"--------------------Topilgan OPlar ro'yhat----------------------\n\n";
yoz<<"OP nomi | OP yili | OP razryad soni | OP turi | OP imkoniyatlari soni | \n";
yoz<<"-----------------------------------------------------------------------------------------\n";
while (it2 != mp.end())
{
int word = it2->first;
komp a = it2->second;
if(a.nomi==a1 || a.yili==b || a.rzr_soni==c || a.turi==d || a.imk_soni==e){
yoz<
}
it2++;
}
}
case 0: {
exit;
}
}
return 0;
}
Do'stlaringiz bilan baham: |