-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSolutionsOf5.c
87 lines (61 loc) · 2.03 KB
/
SolutionsOf5.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include <stdio.h>
// 5 Questions for practice.. To improve in C.
// Q.1 Find a area of circle. Formula: A=πr2 (2 is square)
int main()
{
float radius;
printf("Calculate the area of a circle\n Enter a the radius: ");
scanf("%f", &radius);
float area_of_circle = 3.14 * radius * radius;
printf("Area of the circle is: %f", area_of_circle);
return 0;
}
// Q.2 Find the volume of cylinder. Formula: A=πr2h (2 is square)
int main()
{
float radius;
printf("Calculate the volume of cylinder\nEnter the radius: ");
scanf("%f", &radius);
float height;
printf("Enter The Height: ");
scanf("%f", &height);
float volume_of_cylinder = 3.14 * radius * radius * height;
printf("Volume of cylinder is: %f", volume_of_cylinder);
return 0;
}
// Q.3 Perimter of a rectangle. Formula: perimeter= 2 x (width+height)
int main()
{
float width, height;
printf("Calculate perimeter of rectangle\nEnter the width of rectangle: ");
scanf("%f", &width);
printf("Enter the height of rectangle: ");
scanf("%f", &height);
float perimeter = 2 * (width + height);
printf("The perimeter of rectangle is: %2f", perimeter);
return 0;
}
// Q.4 Convert Temperature from Fahrenheit to Celsius. Formula: °C = 5/9 x (°F - 32)
int main()
{
float fahrenheit, celsius;
printf("Convert Temperature from Fahrenheit to Celsius\nEnter the fahrenheit: ");
scanf("%f", &fahrenheit);
celsius = 5.0 / 9.0 * (fahrenheit - 32);
printf("Celsius converted from fahrenheit : %f", celsius);
return 0;
}
// Q.5 Calculate Simple Interest. Formula: Simple Interest= P×R×T/100
int main()
{
float principal, rate, time;
printf("Calculate the simple interest\nEnter the principal amount: ");
scanf("%f", &principal);
printf("Enter the rate of interest: ");
scanf("%f", &rate);
printf("Enter the time period: ");
scanf("%f", &time);
float simple_interest = principal * rate * time / 100;
printf("Simple interest is: %.2f", simple_interest);
return 0;
}