HW_1

HW_1)

Problem _1:
Description: I included <stdio.h> and <math.h> so that i'm able to code. I had to google how to allow input from the user to convert the desired measurements.I came across "scanf" which allowed input from float. The rest was just simple conversions by assigning values. Rinse and repeat for the rest of the homework given.

/* PRoblem_1                          */
#include <stdio.h>
#include <math.h>
int main ()
{
  float meters, Miles;
  /* inputer meters from user                                 */
  printf ("enter length in meters: ");
  scanf("%f", &meters);
  /* conversion from meters to miles */
  Miles= meters/1609.34;
  printf("length in Miles = %.2f Miles", Miles);
 return 0;

}






Problem_2:
Like I stated I used the same format as the original  using "printf" and "scanf"  to allow input from the user and display text on screen asking for input. I did spend about an hour debugging, because I had an extra semi colin i9n one of my "scanf"

/* Problem_2        */
#include <stdio.h>
#include <math.h>
int main()
{
  float c,f,r;
  printf ("enter celculus (aka hotness index): ");
  scanf("%f", &c);
  /* conversion from celculus to rankan */
  f=(9/5*c)+32;
  r=f+459.67;
  printf("celculus = %.2f rankan", r);
  return 0;

}




Problem 3:
For problem 3 there was the dilemma of having two input variable. Apparently, how to fix this is having "scanf( "%f, %f, &a, &b). This allows us to replace the float value which we assign.

/* Problem_3        */
#include <stdio.h>
#include <math.h>
int main(void)
{
  float a,b,c_area;
  printf ("enter semi axis a and b : ");
  scanf("%f %f", &a, &b);
  /* Finding the area of the ellipse*/
  c_area = M_PI*a*b;
  printf("Area of ellipse = %.2f c", c_area);
  return 0;
}

/* NEVER FORGET SEMI COLIN!!!     */

\






Problem 4: With problem 4 I had to look up how to find the area of a section of an circle, which was essentially the exact same coding for the area of an ellipse. It just used a different formula.



/* Problem_4        */
#include <stdio.h>
#include <math.h>
int main(void)
{
/* Initiliaze input from user   */
  float area,r,d;
  printf ("enter radius and degrees between radii of : ");
  scanf("%f %f", &r, &d);
/* area computation   */
  area = (M_PI*r*r*d)/360;
  printf("Area of sector = %f", area);
  return 0;

}






























































Comments

Popular posts from this blog

Day_13

Day 18 WH