1) for loop
2) do while
Basically it is my assignment. I just need an idea, I don't want to tell me all.
So if you can help me just with addition of vectors, others for multiplication, subtraction and length i can make myself.
Program requirement is that program user will insert the vector components, I can do that, for example if [1,1] and [2,3] are two vectors, then please tell me two way to add them.
1)using for loop
- Code: Select all
int main()
{
int x1, y1, x2, y2;
cout << "\nPlease enter the first componet of 1 vector:";
cin >> x1;
cout << "Please enter the second component of 1 vector:";
cin >> y1;
cout << "\nPlease enter the first component of 2 vetor:";
cin >> x2;
cout << "Please enter the second component of 2 vector:";
cin >> y2;
for (initialization; condition; increment)
cout << "Addition of two vector is " << ((x1+x2) +(y1+y2)) << endl;
return 0;
}
2) using do while
- Code: Select all
int main()
{
int x1, y1, x2, y2;
cout << "\nPlease enter the first componet of 1 vector:";
cin >> x1;
cout << "Please enter the second component of 1 vector:";
cin >> y1;
cout << "\nPlease enter the first component of 2 vetor:";
cin >> x2;
cout << "Please enter the second component of 2 vector:";
cin >> y2;
do
{
cout << "Addition of two vector is " << ((x1+x2) +(y1+y2)) << endl;
}
while (condition);
return 0;
}
I'll be very thankful to you.

