1-topshiriq 1.nxn matritsaning pastki chap uchburchagidagi elementlaridan vektor hosil qiling. #include #include #include using namespace std;
int main() {
int n; n=4;
int a[n][n];
vectorvk;
for(int i=0; ifor(int j=0; ja[i][j]=rand()%9;
if(i>j)vk.push_back(a[i][j]);
}
}
cout<<"Massiv:\n";
for(int i=0; ifor(int j=0; jcout<cout<}
cout<<"******* \n Vektor: \n";
for(int i=0; icout<return 0;
}
1.1- topshiriq
#include using namespace std;
int main(){
double x, y, e=2.7182818285, pi=3.1415926536;
cout<<"x=";
cin>>x;
y=pow((pow(x, 3)+cos(pow(abs(pow(x, 3)), 1/2))), 1/5)+(pow(e, x))/(cos(3*x+pi/15));
cout<<"y="<}
2-topshiriq Ketma-ket qidiruv usulidan foydalanib ro’yhatda har ikkinchi elementni qidiring va taqqoslashlar soninianiqlang. #include using namespace std;
int main(){
int n;
cout<<"n=";
cin>>n;
int k[n];
for(int i=0;icin>>k[i];
int low = 0;
int hi = n-1;
int j=0;
while (low <= hi){
int mid = (low + hi) / 2;
j++;
if (k[1] == k[mid]){
cout<<"qidirilayotgan element "<return 0;
}
if (k[1] < k[mid])
hi = mid - 1;
else low = mid + 1;
}
return 0;
}
3-topshiriq Talabalar familiyalarini alifbo tartibida #include #include using namespace std;
struct ORIN{ int t; string FIO;}; int q=0;
void qs(ORIN *a,int first,int last){
int i = first, j = last;ORIN x =a[(first + last) / 2]; do {
while (a[i].FIO < x.FIO) i++; while (a[j].FIO > x.FIO) j--; if(i <= j) {
if (i < j){ swap(a[i], a[j]);q++;} i++; j--;}
} while (i <= j); if (i < last)
qs(a,i,last); if (first < j) qs(a,first,j);}
int main(int args, char *argv[])
{
int n;cout<<"Talabalar sonini kiriting: ";
cin>>n; ORIN nomer[n];
cout<<"Namuna: Toshpolatov_Shaxzodbek"<for(int i=0;inomer[i].t=i+1;
cin>>nomer[i].FIO;}
qs(nomer,0,n-1);
for(int i=0;icout<cout<}
3.1-topshiriq
“22”, “26”, “14”, “52”, “76”, “45”, “84”, “75”, “15” berilgan butun sonlarni
pufakchali saralash usuli orqali dasturi ishlab chiqilsin va taxlil qilinsin.
#include
using namespace std;
void swap(int *xp, int *yp){
int temp=*xp; *xp=*yp; *yp=temp; }
void p_saralash(int arr[], int n){ int i, j;
for(i=0; i
if(arr[j]>arr[j+1]) swap(&arr[j],&arr[j+1]); }
void printArray(int arr[], int size ){ int i;
for(i=0; i
cout<
cout<
int main(){
int m;
cout<<"Massiv elementlari soni: ";
cin>>m; int arr[m]; cout<<"Massiv elementlarni kiriting: ";
for(int k=0; k
cin>>arr[k];
int n=sizeof(arr)/sizeof(arr[0]);
p_saralash(arr,n);
cout<<"Saralangan massiv elementlari: ";
printArray(arr,n);
return 0; }
4-topshiriq Sonni raqamlar yig`indisini topuvchi rekursiv funksiyatuzing. #include #include using namespace std;
int Raqam_Yigindi(int n) {
int sum=0, r;
for(int i=0; i<=n; i++)
if(n!=0){
r=n%10;
sum += fabs(r) ;
n=n/10 ;
}
return sum ;
}
int main()
{
int n;
cout<<"Sonni kiriting: " ; cin>>n ;
cout <<"Sonning raqamlari yig'indisi: " << Raqam_Yigindi(n);
return 0;
}
4.1-topshiriq Berilgan a va b sonlarining EKUKini topuvchi rekursiv funksiyatuzing. #include using namespace std;
long EKUK(long a, long b) {
if (b != 0) {
long long c = a % b;
a = b;
b = c;
return EKUK(a, b);
}
} int main()
{ int a,b;
cout << "A="; cin>>a;
cout << "B="; cin>>b;
cout << "EKUK(" << a << ";" << b << ")=" << a*b*1./EKUK(a,b) << endl;
return 0;
}
5-topshiriq List elementlari orasidan k indeksdagi elementni topuvchi dastur tuzing. #include using namespace std;
int main()
{
list a;
long n,i,x;
cin>>n;
for (i=0; i {
cin>>x;
a.push_back(x);
}
int k; cin>>k;
int cnt=0;
for (auto i:a){
if (cnt==k-1) cout << i << endl;
cnt++;
}
return 0;
}
6-topshiriq Talaba sinfini dasturda qo‘1lang. Sinfda parametrsiz va parametrli konstruktor, kiritish va chiqarish usullariyaratilsin.
#include
using namespace std;
struct Talaba{
string familiya,ism,mutaxasislik;
int kurs;};
int main()
{
Talaba T[1000];
int n;
cout<<"Talabalar sonini kiriting: ";
cin>>n;
for(int i=1; i<=n; i++)
{ cout<<"Talabani familiyasini kiriting: ";
cin>>T[i].familiya;
cout<<"Talabaning ismini kiriting: ";
cin>>T[i].ism;
cout<<"Talabaning mutaxasisligini kiriting: ";
cin>>T[i].mutaxasislik;
cout<<"Talabaning kursini kiriting: ";
cin>>T[i].kurs; cout<string S;
cout<<"So'ralgan talabaning familiyasini kiriting:";cin>>S;
for(int i=1; i<=n; i++)
{
if(T[i].familiya==S){
cout<<"Talabaning F.I:"<cout<<"Mutaxasislik:"<cout<<"Kursi:"<}else
cout<<"Bunday familiyaga ega talaba mavjud emas!";
break; }
}
6.1-topshiriq Nuqta sinfini yarating. Bu sinf asosida uchburchak sinfini yarating va dasturda qo‘llang. Bu sinfda perimetr, y uzani hisoblash va uchburchakni chizish usullari mavjudbo‘lsin. #include using namespace std;
class nuqta {
long a , b , c;
double p , s ;
public:
nuqta(){};
nuqta(long A, long B, long C){
nuqta::a = A;
nuqta::b = B;
nuqta::c = C;
nuqta::p = (A+B+C);
nuqta::s = sqrt((p*1./2-a)*(p*1./2-b)*(p*1./2-c));
}
void chiqarish(){
cout << "Uchburchak qiymatlari"<cout << "a=" << a << endl;
cout << "b=" << b << endl;
cout << "c=" << c << endl;
cout << "p=" << p << endl;
cout << "s=" << s << endl;
cout << endl;
}};
class uchburchak{
public:
static void uchburchak_kiritish(struct nuqta Triangle[], int n){
long a , b , c;
for (int i=0;icout << "Uchburchak tomonlarini kiriting: " << endl;
cout << "a="; cin >> a;
cout << "b="; cin >> b;
cout << "c="; cin >> c;
cout << endl;
Triangle[i] = nuqta(a,b,c); }}
static void uchburchak_chiqarish(struct nuqta Triangle[], int n){
for (int i=0;iTriangle[i].chiqarish(); }
};
int main() {
nuqta Triangle[] = {
nuqta(6,4,3),
nuqta(6,6,6),
nuqta(6,7,5), };
uchburchak::uchburchak_chiqarish(Triangle, 3);
uchburchak::uchburchak_kiritish(Triangle,1);
uchburchak::uchburchak_chiqarish(Triangle,3);
}
7.1-topshiriq Ntadoiraberilgan.Budoiralardanustma-ustqo‗yganholdapiramidayig‗ilmoqda.Yig‗ishdaularningmarkazlaribittanuqtadaturishilozim.Demak, ntadoiravaularningradiuslariberilgan.Agarularniustma-ustqo‗ygandatepadanqaragandaqaysi radiuslidoiralarniko‗rish mumkin.
Kiruvchi
Chiquvchi
6
6 2 1 5 3 4
6 5 4
6
1 2 3 4 5 6
6
#include using namespace std;
int main()
{
stack a1,a2;
int n,x,i;
cin>>n;
for (i=0; i{
cin>>x;
a1.push(x);
}
int max=a1.top();
a1.pop();
a2.push(max);
while (!a1.empty())
{
if (a1.top()>=max) {
a2.push(a1.top());
a1.pop();
}else a1.pop();
}
while (!a2.empty())
{
cout << a2.top() << " ";
a2.pop();
}
return 0;
}
8-topshiriq Ikkita ro‟yhatbirlashtirilsin.
#include #include #define SIZE(arr) (sizeof(arr) / sizeof(arr[0]))
using namespace std;
struct node {
char data;
struct node *next;
};
node *createList(char *arr, int n){
node *head, *p;
p = head = new node;
head->data = arr[0];
head->next = NULL;
for (int i = 1; i < n; ++i) {
p->next = new node;
p = p->next;
p->data = arr[i];
p->next = NULL;
}
return head;
}
void displayList(node *head){
while (head != NULL) {
cout << head->data << " ";
head = head->next;
}
cout << endl;
}
node *mergeSortedLists(node *head1, node *head2){
node *result = NULL;
if (head1 == NULL) {
return head2;
}
if (head2 == NULL) {
return head1;
}
if (head1->data < head2->data) {
result = head1;
result->next = mergeSortedLists(head1->next, head2);
} else {
result = head2;
result->next = mergeSortedLists(head1, head2->next);
}
return result;
}