fork download
  1. #include <cstdlib>
  2. #include <iostream>
  3. #include <cmath>
  4. #include <memory.h>
  5. using namespace std;
  6.  
  7. struct vect
  8. {
  9. double x,y;
  10.  
  11. };
  12.  
  13. void print(vect* c)
  14. {
  15. cout<<"c("<<c->x<<","<<c->y<<")"<<endl;
  16. }
  17.  
  18. int main()
  19. {
  20. vect a,b,c;//объявим переменные типа Vect
  21. memset(&a,0,sizeof(a));
  22. memset(&b,0,sizeof(b));
  23. memset(&c,0,sizeof(c));
  24. print (&c);
  25. cout<<"vector 1"<<endl;
  26. cin>>a.x;
  27. cin>>a.y;
  28. cout<<" a= " << sqrt(a.x*a.x+a.y*a.y)<<endl;
  29. cout<<"vector 2"<<endl;
  30. cin>>b.x;
  31. cin>>b.y;
  32. cout<<"|b|= "<< sqrt(b.x*b.x+b.y*b.y)<<endl;
  33. cout<<"|a+b|= "<<sqrt((a.x+b.x)*(a.x+b.x)+(a.y+b.y)*(a.y+b.y))<<endl;
  34. cout<<"|a-b|= "<<sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y))<<endl;
  35. cout<<"|a*3| "<< sqrt((a.x*3)*(a.x*3)+(a.y*3)*(a.y*3))<<endl;
  36.  
  37. return 0;
  38. }
Success #stdin #stdout 0s 3432KB
stdin
2
3
4
5
stdout
c(0,0)
vector 1
 a= 3.60555
vector 2
|b|= 6.40312
|a+b|= 10
|a-b|= 2.82843
|a*3| 10.8167