HW 1
Convert meters to miles:
#include <stdio.h>
#include <math.h>
int main(void)
{
float meter, mile;
printf("Meter input: ");
scanf("%f", &meter);
mile = meter * 0.000621371;
printf("Mile output: %5.2f", mile);
return 0;
}
Screenshot:

Convert Celsius to Rankine:
#include <stdio.h>
#include <math.h>
int main(void)
{
float Celsius, Rankine;
printf("Celsius input: ");
scanf("%f", &Celsius);
Rankine = (Celsius * 1.8) + 491.67;
printf("Rankine output: %5.2f", Rankine);
return 0;
}
Screenshot:
Calculate area of ellipse using major and minor axis:
#include <stdio.h>
#include <math.h>
#define PI 3.141593
int main(void)
{
float major, minor, area;
printf("Major (short) axis: ");
scanf("%f", &major);
printf("Minor (short) axis: ");
scanf("%f", &minor);
area = PI*major*minor;
printf("Ellipse area: %5.2f", area);
return 0;
}
Screenshot:
Calculate sector area of circle given angle:
#include <stdio.h>
#include <math.h>
#define PI 3.141593
int main(void)
{
float degrees, area;
again:do {
printf("Degree measurement: ");
scanf("%f", °rees);
if (degrees < 0 || degrees > 360)
{
printf("Invalid angle measurement, try again. \n");
goto again;
}
else
{
area = (degrees / 360)*PI;
printf("Ellipse area: %5.2fr^2", area);
}
}while(degrees < 0 || degrees > 360);
return 0;
}
Screenshot:
#include <stdio.h>
#include <math.h>
int main(void)
{
float meter, mile;
printf("Meter input: ");
scanf("%f", &meter);
mile = meter * 0.000621371;
printf("Mile output: %5.2f", mile);
return 0;
}
Screenshot:
Convert Celsius to Rankine:
#include <stdio.h>
#include <math.h>
int main(void)
{
float Celsius, Rankine;
printf("Celsius input: ");
scanf("%f", &Celsius);
Rankine = (Celsius * 1.8) + 491.67;
printf("Rankine output: %5.2f", Rankine);
return 0;
}
Screenshot:
Calculate area of ellipse using major and minor axis:
#include <stdio.h>
#include <math.h>
#define PI 3.141593
int main(void)
{
float major, minor, area;
printf("Major (short) axis: ");
scanf("%f", &major);
printf("Minor (short) axis: ");
scanf("%f", &minor);
area = PI*major*minor;
printf("Ellipse area: %5.2f", area);
return 0;
}
Screenshot:
Calculate sector area of circle given angle:
#include <stdio.h>
#include <math.h>
#define PI 3.141593
int main(void)
{
float degrees, area;
again:do {
printf("Degree measurement: ");
scanf("%f", °rees);
if (degrees < 0 || degrees > 360)
{
printf("Invalid angle measurement, try again. \n");
goto again;
}
else
{
area = (degrees / 360)*PI;
printf("Ellipse area: %5.2fr^2", area);
}
}while(degrees < 0 || degrees > 360);
return 0;
}
Screenshot:
Comments
Post a Comment