Advertisement
Guest User

Übung 5-01

a guest
Mar 19th, 2019
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. int i ;
  8. int sum =0;
  9. const int n = 4;
  10. int a [n];
  11. int b [n];
  12. int c [n];
  13.  
  14. cout << "Geben Sie die 4 Elemente des ersten Vektors ein" << endl;
  15. for (i=0;i < n;i++){
  16. cout << "a[" << i << "]";
  17. cin >> a[i];
  18. }
  19. cout << "Geben Sie die 4 Elemente des zweiten Vektors ein" << endl;
  20. for (i=0;i < n;i++){
  21. cout << "b[" << i << "]";
  22. cin >> b[i];
  23. }
  24.  
  25. // Vektorsumme
  26. for (i=0;i<n;i++){
  27. c[i] = a[i] + b[i];
  28. cout << "Vektorsumme c["<< i << "] :" << "c[" << c[i] << "]" << endl;
  29. }
  30.  
  31. //Skalarprodukt
  32. for (i=0;i<n;i++){
  33. c[i] = a[i] * b[i];
  34. sum += c[i];
  35. }
  36. cout << "Skalarprodukt = "<< sum << endl;
  37.  
  38.  
  39.  
  40. return 0;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement