Advertisement
syad28

Tutorial 8 Computer Science

Feb 9th, 2015
264
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.33 KB | None | 0 0
  1. ######  ####### ######  #     #    #    ####### ###    #    #     #
  2. #     # #       #     # #     #   # #      #     #    # #   ##    #
  3. #     # #       #     # #     #  #   #     #     #   #   #  # #   #
  4. ######  #####   ######  ####### #     #    #     #  #     # #  #  #
  5. #       #       #   #   #     # #######    #     #  ####### #   # #
  6. #       #       #    #  #     # #     #    #     #  #     # #    ##
  7. #       ####### #     # #     # #     #    #    ### #     # #     #
  8.  
  9. Coding ini dibuat hanya untuk rujukan.Bukannya untuk ditiru bulat².
  10. Sila buat tutorial anda sendiri.Usaha tangga kejayaan.
  11.  
  12. Question 3
  13.  
  14. #include<stdio.h>
  15. void mph_to_kmph(float);
  16. void kmph_to_mph(float);
  17. int main(void)
  18. {
  19.  
  20. int check,sentinel;
  21. float ans,input;
  22. sentinel=1;
  23. while(sentinel==1)
  24. {
  25.  
  26. printf("If you would like to convert from MPH to KMPH,please enter \"1\" and if you would like to convert from KMPH to MPH,please enter \"2\" : ");
  27. scanf("%i",&check);
  28.  
  29. switch(check)
  30. {
  31.     case 1:
  32.             printf("\nPlease enter the speed in MPH : ");
  33.             scanf("%f",&input);
  34.             kmph_to_mph(input);
  35.             break;
  36.     case 2:
  37.             printf("\nPlease enter the speed in KMPH : ");
  38.             scanf("%f",&input);
  39.             mph_to_kmph(input);
  40.             break;
  41. }
  42. printf("\n\nDo you want to continue converting ?\n1 for continue\n");
  43. scanf("%i",&sentinel);
  44. }
  45. return 0;
  46. }
  47.  
  48. void kmph_to_mph(float input)
  49. {   float ans;
  50.     ans=input/1.609344;
  51.     printf("\n%f mph is equal to %f kmph",input,ans);
  52. }
  53.  
  54. void mph_to_kmph(float input)
  55. {   float ans;
  56.     ans=input*1.609344;
  57.     printf("\n%f kmph is equal to %f mph",input,ans);
  58. }
  59.  
  60.  
  61. Question 4
  62.  
  63. #include<stdio.h>
  64. #include<math.h>
  65. #define PI 4.0*atan(1.0)
  66. float degree_to_radian(int);
  67. int main(void)
  68. {
  69.     float radian;
  70.     int degree;
  71.     degree=0;
  72.     printf("Degree\tRadian\n");
  73.     while(degree<360)
  74.     {
  75.         degree+=5;
  76.         radian=degree_to_radian(degree);
  77.         printf("\n%i\t%f",degree,radian);
  78.     }
  79.     return 0;
  80. }
  81.  
  82. float degree_to_radian(int degree)
  83. {   float radian;
  84.     radian=degree*(PI/180);
  85.     return radian;
  86. }
  87.  
  88.  
  89. Question 5
  90.  
  91. #include<stdio.h>
  92. #define c 2.9979E8
  93. void energy(float);
  94. int main(void)
  95. {
  96.     float mass;
  97.     printf("Please enter the value of mass (kg) : ");
  98.     scanf("%f",&mass);
  99.     energy(mass);
  100.  
  101. }
  102.  
  103. void energy(float mass)
  104. {   float E;
  105.     E=mass*c*c;
  106.     printf("\nThe energy required for %.2f kg is %.2E",mass,E);
  107. }
  108.  
  109.  
  110. Question 6
  111.  
  112. #include<stdio.h>
  113. #include<math.h>
  114. float area(float,float,float,float);
  115. float s(float,float,float);
  116. int main(void)
  117. {
  118.     int sentinel;
  119.     float a,b,c,S,AREA;
  120. //LOOP BEGIN
  121. do{
  122.  
  123. //Asking user data (input)
  124.  
  125. printf("Please enter value of a : ");
  126. scanf("%f",&a);
  127. printf("Please enter value of b : ");
  128. scanf("%f",&b);
  129. printf("Please enter value of c : ");
  130. scanf("%f",&c);
  131.  
  132. //Assigning value to "S"
  133. S=s(a,b,c);
  134.  
  135. //Calculating AREA
  136. AREA=area(S,a,b,c);
  137.  
  138. printf("\nThe S value is %f,and the area of the triangle is %f",S,AREA);
  139. printf("\nDo you want to continue ? Hit 1 to continue : ");
  140. scanf("%i",&sentinel);
  141. }while(sentinel==1);
  142. //LOOP ENDS
  143. return 0;
  144. }
  145.  
  146. float s(float a,float b,float c)
  147. {float S;
  148.     S=(a+b+c)/2;
  149.     return S;
  150. }
  151.  
  152. float area(float S,float a,float b,float c)
  153. {float AREA;
  154.     AREA=sqrt(S*(S-a)*(S-b)*(S-c));
  155.     return AREA;
  156. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement