SHARE
TWEET

Untitled

a guest Apr 24th, 2019 59 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include "stdafx.h"
  2. #include <stdio.h>
  3.  
  4.  
  5. void adunare(int x[], int y[], int z[], int n)
  6. {
  7.     for (int i = 0; i<n; i++)
  8.         z[i] = x[i] + y[i];
  9. }
  10. void inmultireScalarVector(int x[],int y[], int a, int b)
  11. {
  12.     for (int i = 0; i < b; i++)
  13.         y[i] = x[i] * a;
  14. }
  15. void imultireMatriceVector(int n,int m){
  16.     int i, j, k;
  17.     int a[4][4]; int b[4]; int c[4];
  18.    
  19.     for (i = 0; i<n; i++) {
  20.         for (j = 0; j<m; j++) {
  21.             printf("a[%d][%d] = ", i, j);
  22.             scanf_s("%d", &a[i][j]);
  23.         }
  24.     }
  25.  
  26.     for (k = 0; k<m; k++) {
  27.         printf("b[%d] = ", k);
  28.         scanf_s("%d", &b[k]);
  29.     }
  30.  
  31.     for (j = 0; j<m; j++) {
  32.         c[j] = 0;
  33.         for (k = 0; k<m; k++) {
  34.             c[j] += b[k] * a[j][k];
  35.         }
  36.     }
  37.  
  38.  
  39.     puts("Vectorul rezultat este: ");
  40.     for (k = 0; k<m; k++) {
  41.         printf("c[%d] = %d \n", k, c[k]);
  42.     }
  43. }
  44.  
  45.  
  46. int _tmain(int argc, _TCHAR* argv[])
  47. {
  48.     int x[4], y[4], z[4], n=4 ;
  49.     int i;
  50.    
  51.     x[0] = 1; x[1] = 2; x[2] = 3; x[3] = 4;
  52.     y[0] = 5; y[1] = 6; y[2] = 7; y[3] = 8;
  53.     adunare(x, y,z,n);
  54.     printf("Adunare 2 vectori: ");
  55.     for (i = 0; i < n; i++) {
  56.         printf("%d ", z[i]);
  57.     }
  58.     printf("\n");
  59.  
  60.     inmultireScalarVector(y,z,2,4);
  61.     printf("Imultire scalar cu vector: ");
  62.     for (i = 0; i < n; i++) {
  63.         printf("%d ", z[i]);
  64.     }
  65.     printf("\n");
  66.    
  67.     imultireMatriceVector(4, 4);
  68.    
  69.     return 0;
  70. }
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