Vous êtes sur la page 1sur 2

1.

/*
2. REG#: FA18-BCE-081
3. NAME:MUHAMMAD TAYYAB
4. CLASS: BCE
5. SECTION: B */
6.
7. // starting of program
8. #include<stdio.h>
9. #include<math.h>
10.
11. void inputs(); //function prototype
12. void calculate_charges();
13. void total();
14.
15.
16.
17. int car[4]= {0,1,2,3}; //declaring and assignning of an array
18. float hours[4],cal_charges[4] = {0,30, 30,30};
19. float total_charges, total_hours=0;
20.
21. int main(void) //starting of main function
22. {
23. inputs(); // calling of function
24. calculate_charges(); // calling of function
25. total(); // calling of function
26. return 0;
27.
28. } //end of main function
29.
30. void inputs() /*this function used to take input*/
31. {
32. int x; //decalring of variable
33. for (x = 1; x<=3; x++)
34.
35. {
36.
37. printf("enter the number of hours for car %d:\n",car[x]);
38. scanf("%f",&hours[x]);
39. } //end FOR
40.
41. } //end funtion of void input
42.
43. void calculate_charges() /*this function used to take input*/
44.
45. {
46. int x, y; //decalring of variable
47. for(x = 1; x <= 3; x++)
48. {
49. if(hours[x] > 3.0)
50. {
51. y = ceil(hours[x])-3;
52. for (;y>0;y--)
53. {
54. cal_charges[x] =cal_charges[x] + 5.00;
55. if( cal_charges[x] ==100.00){
56. break;
57. } // end if
58. } //end for
59. } //end if
60. } //end for
61. } //end funtion of viod calculate_charges()
62. void total()
63. {
64. int x;
65. printf("\ncars\thours\tcal_charges\n");
66. for(x = 1; x<=3; x++)
67. {
68. printf("%2d\t%.2f\t%.2f", cars[x], hours[x], cal_charges[x]);
69.
70. total_charges += cal_charges[x];
71.
72. total_hours += hours[x];
73. }
74. printf("total: .2%f\t.2%f",total_charges,total_hours );
75. }
Output:

Vous aimerez peut-être aussi