LAB1_211
LAB1_211
h>
2 #include <stdlib.h>
3
4 //LAB1
5 //1. Write a C program to find area and perimeter of a rectangle.
6 [area = length *breadth, Perimeter = 2(length + breadth)]
7 int main()
8 {
9 float length, breadth, area, perimeter;
10 printf("enter the value of length\n");
11 scanf("%f", &length);
12 printf("enter the value of breadth\n");
13 scanf("%f", &breadth);
14 area = length * breadth;
15 perimeter = 2 *(length + breadth);
16 printf("\narea = %f\n", area);
17 printf("\nperimeter = %f\n", perimeter);
18
19 return 0;
20 }
21
22 OUTPUT
23 enter the value of length
24 5
25 enter the value of breadth
26 6
27 area = 30.000000
28 perimeter = 22.000000
29
30 //2. Write a C program to calculate simple interest.
31 int main()
32 {
33 float p, r, n, si;
34 printf("\nEnter the profit, rate of interest and no of yr\n");
35 scanf("%f%f%f", &p, &r, &n);
36 si = (p *r *n) / 100;
37 printf("\nSimple Interest=%f", si);
38 return 0;
39 }
40
41 OUTPUT
42
43 Enter the profit, rate of interest and no of yr
44 200
45 20
46 2
47
48 Simple Interest=80.000000
49
50 //3. Write a C program to swap two integers.
51
52 int main()
53 {
54 int x, y, temp;
55 printf("Enter the value of x and y\n");
56 scanf("%d%d", &x, &y);
57 printf("Before Swapping\nx = %d\ny = %d\n", x, y);
58 temp = x;
59 x = y;
60 y = temp;
61 printf("After Swapping\nx = %d\ny = %d\n", x, y);
62
63 return 0;
64
65 }
66
67 OUTPUT
68 Enter the value of x and y
69 3
70 6
71 Before Swapping
72 x = 3
73 y = 6
74 After Swapping
75 x = 6
76 y = 3
77
78 /*4. Write a C program to accept 5 fraction numbers(floating point numbers)
79 and find sum and average of the numbers*/
80
81 int main()
82 {
83 float m1, m2, m3, m4, m5, sum, average;
84 printf("enter the 5 floating numbers");
85 scanf("%f%f%f%f%f", &m1, &m2, &m3, &m4, &m5);
86 sum = m1 + m2 + m3 + m4 + m5;
87 average = sum / 5;
88 printf("sum of 5 floating numbers= %f\n", sum);
89 printf("\n average of 5 floating numbers = %f", average);
90
91 return 0;
92 }
93 OUTPUT
94 enter the 5 floating numbers1.2
95 1.3
96 1.4
97 1.5
98 1.6
99 sum of 5 floating numbers= 7.000000
100 average of 5 floating numbers = 1.400000
101
102 //5. Program to convert temperature from degree centigrade to Fahrenheit
103 //C=(FH-32)/1.8
104 //FH=(1.8*C)+ 32
105 int main()
106 {
107 float celsius, fahrenheit;
108 printf("Enter temp in Celsius : ");
109 scanf("%f", &celsius);
110 fahrenheit = (1.8 *celsius) + 32;
111 printf("\nTemperature in Fahrenheit : %f ", fahrenheit);
112
113 return 0;
114 }
115 OUTPUT
116 Enter temp in Celsius : 35
117 Temperature in Fahrenheit : 95.000000
118