Write a function, polar_to_rec, that uses the structures defined
in Problem 2. Test your
function with various angles and magnitudes.
Problem 2:
#include<stdio.h>
#include<math.h>
struct RectangularCordinate{
float x;
float y;
};
struct PolarCordinate{
float radius;
float theta;
};
struct PolarCordinate rect_to_polar(struct RectangularCordinate rect){
float radius = pow(rect.x*rect.x + rect.y*rect.y,0.5);
float angle = atan(rect.y/rect.x);
struct PolarCordinate pol = {radius,angle};
return pol;
}
int main(){
struct RectangularCordinate rect = {3,4};
struct PolarCordinate pol = rect_to_polar(rect);
printf("Radius: %.2f\n", pol.radius);
printf("Angle: %.2f\n", pol.theta);
}
C code:
#include <stdio.h>
#include<math.h>
// struct RectangularCordinate
struct RectangularCordinate{
float x;
float y;
};
// struct PolarCordinate
struct PolarCordinate{
float radius;
float theta;
};
//struct for convert RectangularCordinate to PolarCordinate
struct PolarCordinate rect_to_polar(struct RectangularCordinate rect){
float radius = pow(rect.x*rect.x + rect.y*rect.y,0.5);
float angle = atan(rect.y/rect.x);
struct PolarCordinate pol = {radius,angle};
return pol;
}
//struct for convert PolarCordinate to RectangularCordinate
struct RectangularCordinate polar_to_rect(struct PolarCordinate pol){
// convert RectangularCordinate using formula m(cos theta + sin theta)
// where m is magnitude.
// where theta is angle.
float x=pol.radius*cos(pol.theta);
float y=pol.radius*sin(pol.theta);
struct RectangularCordinate rect = {x,y};
//return rectangular Cordinate
return rect;
}
//main
int main(){
// initializing a variable
// and assign value x and y
struct RectangularCordinate rect = {3,4};
// and assign value radius and angle
struct PolarCordinate polar = {5.00,0.93};
//call the function rect_to_polar
struct PolarCordinate pol = rect_to_polar(rect);
//call the function polar_to_rect
struct RectangularCordinate rec=polar_to_rect(polar);
// print the value of radius
printf("Radius: %.2f\n", pol.radius);
// print the value of angle
printf("Angle: %.2f\n", pol.theta);
// print the value of x
printf("x: %.1f\n", rec.x);
// print the value of y
printf("y: %.1f\n", rec.y);
return 0;
}
OUTPUT:
Test case 1:input is:
x=3 and y=4
radius=5.00 and angle=0.93

Test case 2:input is:
x=5 and y=6
radius=7.81 and angle=0.88

Test case 3:input is:
x=2 and y=3
radius=3.61 and angle=0.98

Write a function, polar_to_rec, that uses the structures defined in Problem 2. Test your function with...
I wrote a program which computes the area and perimeter of a square, circle, or rectangle. As you will see in my main function, there is a for loop in which the user is supposed to be able repeat the program until they enter "q" to quit. However, my program runs through one time, the prompt appears again, but then it terminates before the user is allowed to respond to the prompt again. I'm not able to debug why this...
Write a complete C program. Define a structure type element_t to represent one element from the periodictable of elements. Components should include the atomic number (aninteger); the name, chemical symbol, and class (strings); a numeric field forthe atomic weight; and a seven-element array of integers for the number ofelectrons in each shell. The following are the components of an element_t structure for sodium.11 Sodium Na alkali_metal 22.9898 2 8 1 0 0 0 0 Have the user enter the data...
So I have a question in regards to my program. I'm learning to program in C and I was curious about the use of functions. We don't get into them in this class but I wanted to see how they work. Here is my program and I would like to create a function for each of my menu options. I created a function to display and read the menu and the option that is entered, but I would like to...
Program Description Write a program that calculates the distance between two places on Earth, based on their latitude and longitude. Prompt the user to enter the latitude and longitude of two places. The Earth’s mean radius is to be taken as 6371.01 km. Use user-defined variables with descriptive names wherever necessary. Following steps will have to be followed: Program must have header comments stating the author of the Program, date, and Program Description. Include the math.h header file Initialize a...
I JUST NEED HELP WITH DISPLAY PART!
please help!
thanks in advance
// This function saves the array of structures to file. It is already implemented for you.
// You should understand how this code works so that you know how to use it for future assignments.
void save(char* fileName)
{
FILE* file;
int i;
file = fopen(fileName, "wb");
fwrite(&count, sizeof(count), 1, file);
for (i = 0; i < count; i++)
{
fwrite(list[i].name, sizeof(list[i].name), 1, file);
fwrite(list[i].class_standing, sizeof(list[i].class_standing), 1, file);...
13. Write the program with at least two functions to solve the following problem (excluding the main function). The members of a board are considering voting for a tax increase for 100 items. They are considering an increase of 5% for each item. Write a program that will prompt for and accept the current price for each item, then calculate and display their individual price after tax increases. At the end of the program, print the total price before and...
NEED CODE HELPS WITH C PROGRAMMING. ISSUES EXPLAINED IN BOLD. COMPARING TWO LETTERS AND CALLING A FUNCTION. Problem are explained in bold #include <stdio.h> #include <string.h> #include <stdlib.h> #define pi 3.1415 void Area (double n); void VolSphere (double n); void Circumference (double n); void AllCalc (); // i dont know if the declaration of the function is correct AllCalc = AllCalculations //function main begins program execution int main (void) { puts("-Calculating Circle Circumference, Circle Area or Sphere Volume-\n"); void (*f[4])...
Please, I need help, I cannot figure out how to scan variables
in to the function prototypes!
******This is what the program should look like as it runs but I
cannot figure out how to successfully build the code to do
such.******
My code:
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <math.h>
#include <conio.h>
float computeSeriesResistance(float R1, float R2, float R3);
float computeParallelResistance(float R1, float R2, float
R3);
float computeVoltage(int current, float resistance);
void getInputR(float R1, float R2, float R3);
void getInputCandR(int...
Hello, I am having trouble with a problem in my C language class. I am trying to make a program with the following requirements: 1. Use #define to define MAX_SIZE1 as 20, and MAX_SIZE2 as 10 2. Use typedef to define the following struct type: struct { char name[MAX_SIZE1]; int scores[MAX_SIZE2]; } 3. The program accepts from the command line an integer n (<= 30) as the number of students in the class. You may assume that the...
Please I need help in C language, I am trying to modify the code per the below instructions, but I am getting errors. Can't fgure it out. The attempted code modification and data file is privided below, after the instructions. Thank you. Instructions: 1. First, add a function named printMsg that displays a message, a greeting, or an introduction to the program for the user. Add a statement that calls that function from the main function when your program starts....