TGINSIGHT CHAT
Computer Programming
@cpp_sirius
Education- Programming Lessons - Daily problems - Guide books Murojaat: @asadbek_tolqinjonov
Siste innlegg
Tag: #include · 7 innlegg
Publisert 11. des.
#include <iostream> using namespace std; int main() { int n; cin >> n; int arr[n]; for (int i = 0; i < n; i++) { cin >> arr[i]; } int temp = arr[n-1]; for (int i = n-1; i > 0; i--) { arr[i] = arr[i-1]; } arr[0] = temp; for (int i = 0; i < n; i++) { cout << arr[i] << " "; } return 0; }
Hashtags
Publisert 11. des.
#include <iostream> #include <vector> using namespace std; int main() { int n; cin >> n; int sum=0; int matrix[n][100]; for (int i = 0; i < n; i++) { sum = 0; for (int j = 0; j < n; j++) { cin >> matrix[i][j]; sum += matrix[i][j]; } } int sum2 = 0; bool magic = true; // row-based checking for (int i = 0; i < n-1; i++) { sum2 = 0; for (int j = 0; j < n; j++) { sum2 += matrix[i][j]; } if (sum2 != sum) { magic = false; cout << "Not Magic Square" << endl; break; } } // column based-cheking if (magic) { for (int i = 0; i < n; i++) { sum2 = 0; for (int j = 0; j < n; j++) { sum2 += matrix[j][i]; } if (sum2 != sum) { magic = false; cout << "Not Magic Square" << endl; break; } } } // diagonal based checking if (magic) { sum2 = 0; int sum3 = 0; for (int i = 0; i < n; i++) { sum2+=matrix[i][i]; sum3+=matrix[i][n-1-i]; } if (sum2 != sum) { magic = false; cout << "Not Magic Square" << endl; }else if (sum3 != sum) { magic = false; cout << "Not Magic Square" << endl; } } if (magic) { cout << "Magic Square" << endl; } return 0; }
Hashtags
Publisert 6. des.
#include <iostream> #include <cmath> #include <fstream> using namespace std; int calculate(int, int); void swap(int* a, int* b) { *a = *a+*b; *b = *a-*b; *a = *a-*b; } void checkEven(int *num) { if (*num % 2 == 0) { *num = 0; } } void writeLog() { ofstream outputFile("log.txt"); if (outputFile.is_open()) { outputFile << "Finished"; outputFile.close(); } } void printMatrix(int matrix[2][3]) { for (int i = 0; i < 2; i++) { for (int j=0; j < 3; j++) { cout << matrix[i][j] << " "; } cout << endl; } } int main() { // bool flag = true; // int j=5; // for (j; j<10 and flag; j++) { // if (j==7) { // flag = false; // } // cout << j << " "; // } // not ! // or || // and && // ifstream inFile("input.txt"); // string word; // while (inFile >> word) { // cout << word <<endl; // } // ifstream inFile("input.txt"); // string word; // while (getline(inFile, word)) { // cout << word <<endl; // } // int x = 10; // checkEven(&x); // cout<<x; // p1 // int score = 75; // if (score>=60) { // cout<<"Pass"; // }else { // cout<<"Fail"; // } // p2 // int i = 10; // do { // cout << " "<< i; // i--; // }while (i>=7); // p3 // int a=3, b=4; // int result = calculate(a, b); // cout << result << endl; // p4 // int data[] = {10, 20, 30}; // int sum = 0; // for (int i=0; i<sizeof(data)/sizeof(int); i++) { // sum += data[i]; // } // cout << sum << endl; // p5 // bool is_raining = true; // double d=9.8; // if (!is_raining) { // cout<<"Sun"; // }else { // int x = int(d); // cout<<x; // } // double d = 9.17; // int x = round(d); // cout<<x<<endl; // p6 // int num = 42; // int *ptr = # // cout<<*ptr; // p7 // int **arr = new int *[5]; // arr[2] = new int[50]; // delete[] arr; // p9 // int val = 10; // int val2 = 20; // int const * const p = &val; // p = &val2; // cout<<&val<<endl; // cout<<p; // code 2 // int arr[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 9};; // int *ptr = arr; // int max = *arr; // for (int* i = arr; i < arr+10; i++) { // if (*i > max) { // max = *i; // } // } // int max2 = *ptr; // for (int* i=arr; i < arr+10; i++) { // if (*i>max2 and *i<max) { // max2 = *i; // } // } // cout << max2 << endl; // sorting // int n; cout<<"Enter the size of array: "; cin>>n; // int arr[n]; // for (int i = 0; i < n; i++) { // cin>>arr[i]; // } // int *ptr = arr; // for (int i = 1; i < n; i++) { // for (int j = 1; j < n; j++) { // if (*(ptr+j)<*(ptr+j-1)) { // swap(ptr+j, ptr+j-1); // } // } // } // int max2 = *(ptr+n-2); // cout << max2 << endl; // 3-usul // int arr2[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 9}; // int *ptr = arr2; // int max1 = *ptr; // int max2 = 0; // for (int i = 0; i < 10; i++) { // if (max1 < *(ptr+i)) { // max2 = max1; // max1 = *(ptr+i); // } // } // cout<<max2<<endl; return 0; } int calculate(int x, int y) { return x*x + y; }
Hashtags
Publisert 7. okt.
#include <iostream> #include <math.h> using namespace std; // Fun Simple 1 float PowerA3(float x){ return pow(x,3); } //int main(){ // float a, b, c; // int d, e; // cout<<"a = "; cin>>a; // cout<<PowerA3(a)<<endl; // // cout<<"b = "; cin>>b; // cout<<PowerA3(b)<<endl; // // cout<<"c = "; cin>>c; // cout<<PowerA3(c)<<endl; // // cout<<"d = "; cin>>d; // cout<<PowerA3(d)<<endl; // // cout<<"e = "; cin>>e; // cout<<PowerA3(e)<<endl; // return 0; //} // Fun Simple 5 void RectSP(int, int, int, int, int*, int*); // header void RectSP(int x1, int y1, int x2, int y2, int *S, int *P){ int l, w; l = abs(y1-y2); w = abs(x1-x2); *S = l*w; *P = 2*(l+w); } int main(){ int x1, y1, x2, y2, y, p; cout<<"Birinchi nuqta: "; cin>>x1>>y1; cout<<"Ikkinchi nuqta: "; cin>>x2>>y2; RectSP(x1, y1, x2, y2, &y, &p); cout<<"Yuza: "<<y<<endl; cout<<"Perimetr: "<<p<<endl; return 0; }
Hashtags
Publisert 7. okt.
#include <iostream> #include <math.h> using namespace std; // Ko'rsatkichli parametrlar -> Qiymat qaytarmaydigan void Yigindi(int a, int b, int *yig){ *yig = a+b; } int main(){ int x, y, z; cout<<"Enter the numbers: "; cin>>x>>y; Yigindi(x, y, &z); cout<<"Sum: "<<z; return 0; } // callByReference
Hashtags
Publisert 7. okt.
#include <iostream> #include <math.h> using namespace std; // 1. // Qiymat qaytaradigan // ParametrLI funksiya float Yigindi1(float a, float b){ int yig; yig = a+b; return yig; } // 2. // Qiymat qaytaradigan // ParmetrSIZ funksiya float Yigindi2(){ int a, b, yig; cout<<"Enter the numbers: "; cin>>a>>b; yig = a+b; return yig; } // 3. // Qiymat qaytarmaydigan // ParametrLI funksiya void Yigindi3(int a, int b){ int yig; yig = a+b; cout<<"Sum = "<<yig; } // 4. // Qiymat qaytarmaydigan // ParametrSIZ funksiya void Yigindi4(){ int a, b, yig; cout<<"Enter the numbers: "; cin>>a>>b; yig = a+b; cout<<"Sum: "<<yig; } int main(){ // 1. qaytaradigan, parametrli // int a, b, yig; // cout<<"Enter the numbers: "; cin>>a>>b; // yig = Yigindi1(a, b); // cout<<"Sum: "<<yig; // 2. qaytaradigan, parametrsiz // int yig; // yig = Yigindi2(); // cout<<"Sum: "<<yig; // 3. qaytarmaydigan, parametrli // int a, b; // cout<<"Enter the numbers: "; cin>>a>>b; // Yigindi3(a, b); // 4. qaytarmaydigan, parametrsiz // Yigindi4(); return 0; }
Hashtags
Publisert 7. okt.
#include <iostream> #include <math.h> using namespace std; float Ayirma(float a, float b){ float ayir; ayir = a-b; return ayir; } int main(){ int qw, we, ayirma; cout<<"Enter the numbers: "; cin>>qw>>we; ayirma = Ayirma(qw, we); cout<<ayirma; return 0; }
Hashtags