Advertisement
Guest User

Untitled

a guest
Aug 12th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.95 KB | None | 0 0
  1. #include <iostream>
  2. #include <time.h>
  3. #include <stdio.h>
  4. #include <windows.h>
  5.  
  6.  
  7. using namespace std;
  8.  
  9.  
  10. void sommavettori(int[], int [], int);
  11.  
  12.  
  13.  
  14. int main()
  15. {
  16.     srand(time(0));
  17.     int dim=5;
  18.     int vet1[dim], vet2[dim];
  19.  
  20.     for(int ciccio=0; ciccio<dim; ciccio++)
  21.     {
  22.         vet1[ciccio]=rand()%11;
  23.         vet2[ciccio]=rand()%11;
  24.  
  25.     }
  26.  
  27.     sommavettori(vet1, vet2, dim);
  28.  
  29. }
  30.  
  31. void sommavettori(int vet1[], int vet2[], int dim)
  32. {
  33.  
  34.     int vetsomma[dim];
  35.  
  36.     cout << "Vet1= ";
  37.     for(int i=0; i<dim; i++)
  38.     {
  39.         cout << vet1[i] << "-";
  40.     }
  41.     cout << endl;
  42.  
  43.  
  44.  
  45.     cout << "Vet2= ";
  46.     for(int i=0; i<dim; i++)
  47.     {
  48.         cout << vet2[i] << "-";
  49.     }
  50.     cout << endl;
  51.  
  52.  
  53.  
  54.  
  55.     for(int i=0; i<dim; i++)
  56.     {
  57.         vetsomma[i]=vet1[i]+vet2[i];
  58.  
  59.     }
  60.  
  61.     cout << "VetSomma= ";
  62.     for(int i=0; i<dim; i++)
  63.     {
  64.  
  65.         cout << vetsomma[i] << "-";
  66.  
  67.     }
  68.     cout<<endl;
  69.  
  70.  
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement