daily pastebin goal
92%
SHARE
TWEET

kirill

a guest May 24th, 2018 71 in 3 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. int main() {
  5.     FILE *input = fopen("input.txt", "r");
  6.     FILE *output = fopen("output.txt", "w");
  7.  
  8.     int n;
  9.     fscanf(input, "%d", &n);
  10.  
  11.     int vector_sum[4] = {0};
  12.     int vector_current[4] = {0};
  13.  
  14.     for (int i = 0; i < n; ++i) {
  15.         fscanf(input, "%d %d %d %d", &vector_current[0], &vector_current[1], &vector_current[2], &vector_current[3]);
  16.  
  17.         for (int j = 0; j < 4; ++j) {
  18.             vector_sum[j] += vector_current[j];
  19.         }
  20.  
  21.         double length = 0;
  22.         for (int j = 0; j < 4; ++j) {
  23.             length += vector_current[j] * vector_current[j];
  24.         }
  25.         length = sqrt(length);
  26.         fprintf(output, "Длина вектора %d = %lf\n", i+1, length);
  27.     }
  28.  
  29.     fprintf(output, "Сумма векторов = (%d, %d, %d, %d)", vector_sum[0], vector_sum[1], vector_sum[2], vector_sum[3]);
  30.  
  31.     fclose(input);
  32.     fclose(output);
  33.  
  34.     return 0;
  35. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top