![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Jan 2008
Posts: 9
Rep Power: 0
![]() |
Program I did for a class today...did I do it correctly?
Instructions:
I. The program asks for the user to input the magnitudes and angles (with respect to X-axis) for two vectors, A and B. It then calculates the resultant vector (R) by summing the X- and Y-components of the two vectors, and prints the magnitudes, and angles (with respect to X-axis) of the vectors A, B, and R on the screen in the format given below. II. Helpful Math Hints Rad_A = Deg_A * PI/180 Rx = A cos (rad_A) + B cos(rad_B) Ry = A sin (rad_A) + B sin(rad_B) R = √ (Rx^2 + Ry^2), and rad_R = [atan(Ry/Rx)*180/PI] III. Helpful Programming Hints: 1. Preprocessor define PI = 3.14159 2. Define variables A, B, R, deg_A, rad_A, deg_B, Rad_B, deg_R, rad_R, Rx, Ry as "double/or float" 3. Ask user to enter A in newtons, read the value and assign to A; ask to enter deg_A in degrees, read the value (scan in lf format/or float number as appropriate) and assign to deg_A, and so on...for all the input variables. 4. Computer the rad_A, rad_B, and computer the components (Rx and Ry) of the resultant (R): 5. Computer the resultant vector's magnitude: R = √ (Rx^2 + Ry^2) 6. Compute the resultant vector's directions in degrees: #include <stdio.h>
#include <math.h>
#define PI 3.14159
int main()
{
double A,B,R,deg_A,rad_A,deg_B,rad_B,deg_R,rad_R,Rx,Ry;
printf("*My name* 2441203 SA33\n");
printf("ESC151 Spring 08\n");
printf("Recitation 1 Jan 28, 2008\n\n\n");
printf("Enter magnitude of A in newtons \n");
scanf("%lf", &A);
printf("Enter direction of A in degrees \n");
scanf("%lf", °_A);
printf("Enter magnitude of B in newtons \n");
scanf("%lf", &B);
printf("Enter direction of B in degrees \n");
scanf("%lf", °_B);
rad_A=deg_A*PI/180;
rad_B=deg_B*PI/180;
Rx=A*cos(rad_A)+B*cos(rad_B);
Ry=A*sin(rad_A)+B*sin(rad_B);
R=sqrt(Rx*Rx+Ry*Ry);
deg_R=atan(Ry/Rx)*180/PI;
printf("Force(N) Direction(degrees) \n");
printf("A %lf %lf\n",A,deg_A);
printf("B %lf %lf\n",B,deg_B);
printf("R %lf %lf\n:,R,deg_R);
return 0;
} |
|
|
|
|
|
#2 |
|
Programming Guru
![]() |
Re: Program I did for a class today...did I do it correctly?
Why don't you tell me?
It looks promising, but you have a typo on your last printf statement. Literals are terminated with a quotation mark. Not a colon. See what happens when you input: 1 270 1 180 You get an answer in the first quadrant. The answer should be in the third quadrant (225) with magnitude sqrt(2). Do you need to account for this? |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| template class | brad sue | C++ | 1 | Mar 25th, 2007 5:46 PM |
| Language display in program | Prm753 | C++ | 3 | May 30th, 2006 5:45 PM |
| Creating a program to test a program | sixstringartist | C | 8 | Jan 21st, 2006 1:15 PM |
| Problem Compiling this program | OUfanAP12 | Java | 4 | Nov 7th, 2005 7:27 PM |
| grading program | Rsitapara | C++ | 8 | Feb 27th, 2005 11:42 PM |