Advertisement
syad28

Tutorial 4 Computer Science [Updated 26.3.15]

Dec 20th, 2014
367
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 5.17 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. /*Ingat yer,kalau nak print simbol "%" dalam C,kena buat mcm ni "%%" sebab nnti takut codeblock salah paham,nnti codeblock igt korg nak buat something mcm %i,%f,%c,%s pulak...*/
  13.  
  14.  
  15. Question 1
  16.  
  17. #include<stdio.h>
  18. int main(void)
  19. {
  20.  
  21.     float weight,height,BMI;
  22.  
  23.     printf("Please enter your weight(kg) : ");
  24.     scanf("%f",&weight);
  25.     printf("\nPlease enter your height (m) : ");
  26.     scanf("%f",&height);
  27.     BMI=weight/(height*height);
  28.     if (BMI<18.5)
  29.         printf("\n\nYour BMI is %.2f.You are underweight",BMI);
  30.     else if (BMI<25)
  31.         printf("\nYour BMI is %.2f.You are normal",BMI);
  32.     else if (BMI<30)
  33.         printf("\nYour BMI is %.2f.You are overweight",BMI);
  34.         else
  35.         printf("Your BMI is %.2f.You are obese",BMI);
  36.  
  37. printf("\n\n _____ _           _      _     _ _____                 _ ");
  38. printf("\n/  ___| |         (_)    | |   (_)  ___|               | |");
  39. printf("\n\\ `--.| |__  _   _ _  ___| |__  _\\ `--. _   _  __ _  __| |");
  40. printf("\n `--. \\ '_ \\| | | | |/ __| '_ \\| |`--. \\ | | |/ _` |/ _` |");
  41. printf("\n/\\__/ / | | | |_| | | (__| | | | /\\__/ / |_| | (_| | (_| |");
  42. printf("\n\\____/|_| |_|\\__,_|_|\\___|_| |_|_\\____/ \\__, |\\__,_|\\__,_|");
  43. printf("\n                                         __/ |            ");
  44. printf("\n                                        |___/             ");
  45. printf("\n                                                          ");
  46.  
  47.         return 0;
  48. }
  49.  
  50.  
  51. Question 2
  52.  
  53. #include<stdio.h>
  54. int main(void)
  55. {
  56.     int teacher;
  57.     float total_purchase,tax,new_total,final_total,teacher_disc;
  58.  
  59.     printf("Is the buyer a teacher ? Enter \"1\" for true and \"0\" for false : ");
  60.     scanf("%i",&teacher);
  61.     printf("\nPlease enter the total purchase : ");
  62.     scanf("%f",&total_purchase);
  63.  
  64.     //The printing starts here
  65.     printf("\nTotal Purchase  %20.2f",total_purchase);
  66.     if (teacher==1)
  67.     {
  68.         if (total_purchase>=100)
  69.         {
  70.             teacher_disc=0.12*total_purchase;
  71.             printf("\nTeacher's discount (12%%)  %10.2f",teacher_disc);
  72.         }
  73.         else
  74.         {
  75.             teacher_disc=0.1*total_purchase;
  76.             printf("\nTeacher's discount (10%%)  %10.2f",teacher_disc);
  77.         }
  78.         new_total=total_purchase-teacher_disc;
  79.     }
  80.     else
  81.         new_total=total_purchase;
  82.     tax=0.05*new_total;
  83.     printf("\nSales tax (5%%)  %20.2f",tax);
  84.     final_total=new_total-tax;
  85.     printf("\nTotal  %29.2f",final_total);
  86.  
  87. printf("\n\n _____ _           _      _     _ _____                 _ ");
  88. printf("\n/  ___| |         (_)    | |   (_)  ___|               | |");
  89. printf("\n\\ `--.| |__  _   _ _  ___| |__  _\\ `--. _   _  __ _  __| |");
  90. printf("\n `--. \\ '_ \\| | | | |/ __| '_ \\| |`--. \\ | | |/ _` |/ _` |");
  91. printf("\n/\\__/ / | | | |_| | | (__| | | | /\\__/ / |_| | (_| | (_| |");
  92. printf("\n\\____/|_| |_|\\__,_|_|\\___|_| |_|_\\____/ \\__, |\\__,_|\\__,_|");
  93. printf("\n                                         __/ |            ");
  94. printf("\n                                        |___/             ");
  95. printf("\n                                                          ");
  96.  
  97.     return 0;
  98. }
  99.  
  100.  
  101.  
  102. Question 3
  103.  
  104. #include<stdio.h>
  105. int main(void)
  106. {
  107.     char initial1,initial2,initial3;
  108.     float amount_due,days_due;
  109.  
  110.     printf("Please enter your initials (3) : \n");
  111.     scanf("%c%c%c",&initial1,&initial2,&initial3);
  112.     printf("\nPlease enter your amount due : ");
  113.     scanf("%f",&amount_due);
  114.     printf("\nPlease enter the number of days overdue : ");
  115.     scanf("%f",&days_due);
  116.  
  117.     printf("\n\n%c%c%c,",initial1,initial2,initial3);
  118.     if (days_due<=30)
  119.         printf("your penalty is 5%% hence, you have to pay %.2f",1.05*amount_due);
  120.     else if (days_due<=60)
  121.         printf("your penalty is 12%% hence, you have to pay %.2f",1.12*amount_due);
  122.     else
  123.         printf("your penalty is 21%% hence, you have to pay %.2f",1.21*amount_due);
  124.  
  125. printf("\n\n _____ _           _      _     _ _____                 _ ");
  126. printf("\n/  ___| |         (_)    | |   (_)  ___|               | |");
  127. printf("\n\\ `--.| |__  _   _ _  ___| |__  _\\ `--. _   _  __ _  __| |");
  128. printf("\n `--. \\ '_ \\| | | | |/ __| '_ \\| |`--. \\ | | |/ _` |/ _` |");
  129. printf("\n/\\__/ / | | | |_| | | (__| | | | /\\__/ / |_| | (_| | (_| |");
  130. printf("\n\\____/|_| |_|\\__,_|_|\\___|_| |_|_\\____/ \\__, |\\__,_|\\__,_|");
  131. printf("\n                                         __/ |            ");
  132. printf("\n                                        |___/             ");
  133. printf("\n                                                          ");
  134.  
  135.  
  136.         return 0;
  137. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement