Tuesday, September 11, 2018

Homework 1

Meters to Miles

#include <stdio.h>
#include <math.h>
int main(void)
{

/* Declare and initialize variables. */
double dist_meter, dist_mile;

/* Get user input from the keyboard. */
printf("Enter distance in meters: \n");
scanf("%lf",&dist_meter);

/* Convert meter to miles*/
dist_mile = dist_meter * 0.000621371;
printf("\n%lf meters is equivalent to %lf miles\n", dist_meter, dist_mile);

/* Exit program. */
return 0;
}
/*––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––*/

Convert Celsius to Rankine

#include <stdio.h>
#include <math.h>
int main(void)
{

/* Declare and initialize variables. */
double celsius, fahrenheit, rankine;

/* Get user input from the keyboard. */
printf("Enter temperature in Celsius: \n");
scanf("%lf",&celsius);

/* Convert celsius to rankine*/
fahrenheit = celsius * 9/5 + 32;
rankine = fahrenheit + 459.67;
printf("\n%lf Celsius is equivalent to %lf Rankine \n", celsius, rankine);

/* Exit program. */
return 0;
}
/*––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––*/

Area of a Ellipse
#include <stdio.h>
#include <math.h>
int main(void)
{
/* Declare and initialize variables. */
double semi_major, semi_minor, area_ellipse;

#define PI 3.141593
/* Get user input from the keyboard. */
printf("Enter values in meters to calculate area of an ellipse.\n");
printf("\nEnter length of semiaxis a: \n");
scanf("%lf",&semi_major);
printf("Enter length of semiaxis b: \n");
scanf("%lf", &semi_minor);

/* Compute area of ellipse*/
area_ellipse = PI * semi_major * semi_minor;
printf("\nThe area of the ellipse is %lf meters squared\n", area_ellipse);
/* Exit program. */
return 0;
}
/*––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––*/

Area of a Sector of a Cirle

#include <stdio.h>
#include <math.h>
int main(void)
{

/* Declare and initialize variables. */
double angle_sector, radius, area_sector;
#define PI 3.141593

/* Get user input from the keyboard. */
printf("Enter value in meters to calculate area of a sector.\n");
printf("Enter length of radius of your circle: \n");
scanf("%lf",&radius);
printf("\nEnter value in degrees for angle of a sector.\n");
printf("Enter angle of your sector: \n");
scanf("%lf", &angle_sector);

/* Compute area of sector*/
area_sector = (angle_sector / 360) * (PI * radius * radius);
printf("\nThe area of the sector is %lf meters squared.\n", area_sector);

/* Exit program. */
return 0;
}
/*––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––*/

No comments:

Post a Comment