Thursday, August 30, 2018

First prgramming homework

1)
/*-----------------------------------------------------------------------------------*/
/* This program computes the */
/* convertion between meters and miles */
#include <stdio.h>
#include <math.h>
int main (void)
{
/* Declare and initialize variables. */
float meter;
/* The amount of miles wanted */
double mile=1;
/* Compute the equivalent. */
meter=6.21371e-4*mile;
/* Print distance. */
printf("One meter is " "%1.9f \n" "miles",meter);
/* Exit program. */
return 0;
}
/*------------------------------------------------------------------------------------*/

2)
/*-----------------------------------------------------------------------------------*/
/* This program computes the convertion between degrees Celsius and degrees Rankine */
#include <stdio.h>
#include <math.h>
int main (void)
{
/* Declare and initialize variables. */
double Celsius=0, Rankine;
/* Formula to convet */
Rankine = (9/5)*Celsius + 491.67;
/* Print temperature. */
printf("The temperature when it is 0 degrees Celsius is " "%5.2f \n" " degrees Rankine",Rankine);
/* Exit program. */
return 0;
}
/*-----------------------------------------------------------------------------------*/

3)
/*-----------------------------------------------------------------------------------*/
/* This program computes the the area of an ellipse with semiaxes a and b*/
#include <stdio.h>
#include <math.h>
int main (void)
{
/* Declare and initialize variables. */
/* Values for the axis may vary */
double Area, axis_1=4, axis_2=2, Pi=3.1415;
/* Formula to find area */
Area = Pi*axis_1*axis_2;
/* Print area. */
printf("The area of the ellipse has an axis of 4 and another one of 2 is " "%5.2f \n" " units",Area);
/* Exit program. */
return 0;
}
/*-----------------------------------------------------------------------------------*/

4)
/*-----------------------------------------------------------------------------------*/
/* This program computes the the area of a sector of a circle when 33 is the angle in degrees between the radii. */
#include <stdio.h>
#include <math.h>
int main (void)
{
/* Declare and initialize variables. */
/* Values for the radius and angle may vary */
double Area, theta=33, radius=5.5;
/* Formula to find area */
Area = (radius*radius*theta)/2;
/* Print area. */
printf("The area of the sector of a circle with a radius of 5.5 and an angle of 33 degrees is " "%5.3f \n" " units squared",Area);
/* Exit program. */
return 0;
}
/*-----------------------------------------------------------------------------------*/

No comments:

Post a Comment