Advertisement
NikolaDimitroff

Intro to Programming, 01.14.2014

Jan 13th, 2014
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.70 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5.  
  6. const int size = 3;
  7. int matrix1[3][3] = {
  8.     { 1, 2, 3 },
  9.     { 4, 5, 6 },
  10.     { 7, 8, 9 }
  11. };
  12. int matrix2[3][3] = {
  13.     { 1, 2, 3 },
  14.     { 4, 5, 6 },
  15.     { 7, 8, 9 }
  16. };
  17. void multiply(int* matrix1, int* matrix2)
  18. {
  19.     int result[size][size];
  20.     for (int i = 0; i < size; ++i)
  21.     {
  22.         for (int j = 0; j < size; j++)
  23.         {
  24.             result[i][j] = 0;
  25.             for (int k = 0; k < size; k++)
  26.             {
  27.                 result[i][j] += matrix1[i * size + k] * matrix2[k * size + j];
  28.             }
  29.            
  30.         }
  31.     }
  32.     for (int i = 0; i < size; i++)
  33.     {
  34.         for (int j = 0; j < size; j++)
  35.         {
  36.             cout << result[i][j] << " ";
  37.         }
  38.         cout << endl;
  39.     }
  40. }
  41. double computeLength(double x1, double x2, double y1, double y2)
  42. {
  43.     return sqrt((x1 - x2)*(x1 - x2) + (y1 - y2)*(y1 - y2));
  44. }
  45.  
  46. bool isTriangle(double a, double b, double c)
  47. {
  48.     if ((a + b) > c && a + c > b && b + c > a)
  49.         return true;
  50.     else return false;
  51. }
  52.  
  53. int readarray(int* array)
  54. {
  55.     int size;
  56.     cin >> size;
  57.     for (int i = 0; i < size; ++i)
  58.         cin >> array[i];
  59.     return size;
  60. }
  61.  
  62. void writearray(int* array, int size)
  63. {
  64.     for (int i = 0; i < size; i++)
  65.         cout << array[i]<<" ";
  66. }
  67.  
  68. void strcat(char* destination, char* source)
  69. {
  70.     int destinationLength = 0;
  71.     while (destination[destinationLength] != '\0')
  72.     {
  73.         destinationLength++;
  74.     }
  75.     int sourceLength = 0;
  76.     while (source[sourceLength] != '\0')
  77.     {
  78.         destination[destinationLength] = source[sourceLength];
  79.         destinationLength++;
  80.         sourceLength++;
  81.     }
  82.     destination[destinationLength] = '\0';
  83. }
  84. int main(int argc, char** argv)
  85. {
  86.     char text[1000000] = "tova e text";
  87.     char* toAppend = "appendme";
  88.     for (int i = 0; i < 100000; i++)
  89.     {
  90.         strcat(text, toAppend);
  91.     }
  92.  
  93.     cout << text << endl;
  94.     return 0;
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement