 #### Exercise 1 Set A

Apply all the three program development steps for the following examples.

1. Accept dimensions of a cylinder and print the surface area and volume.
(Hint: surface area = 2πr2  + 2πrh, volume = πr2h)

```#include &amp;lt;stdio.h&amp;gt;
#include &amp;lt;math.h&amp;gt;
int main()
{
float surface_area, volume;
printf("Enter  value for  radius and height of a cylinder:");
surface_area = 2 * (22 / 7) * radius * (radius + height);
printf("\nSurface area of cylinder is: %f", surface_area);
printf("\nVolume of cylinder is : %f", volume);
}
```
 \$ gcc vol.c \$ ./a.out Enter value for radius and height of a cylinder: 3 3 Surface area of cylinder is: 108.000000 Volume of cylinder is : 81.000000 \$

2. Accept temperatures in Fahrenheit (F) and print it in Celsius(C) and Kelvin (K).
(Hint: C=5/9(F32), K = C + 273.15)

```#include&amp;lt;stdio.h&amp;gt;
int main()
{
float cel,fer,kel;

printf("Enter Temperature in Fahrenheit :");
scanf("%f",&amp;amp;fer);

cel= (fer-32)/1.8 ;
printf("Celsius = %f \n",cel);

kel = (fer-32)/1.8 + 273.15 ;
printf("Kelvin  = %f \n",kel);

return (0) ;
}
```
 Enter value for radius and height of a cylinder : 4 6 Surface area of cylinder is: 240.000000 Volume of cylinder is : 288.000000

3. Accept initial velocity (u), acceleration (a) and time (t). Print the final velocity (v) and the distance (s) travelled.

(Hint: v = u + at, s = u + at2)

```include&amp;lt;stdio.h&amp;gt;
void main()
{
int sec;
float distance , initial_velocity,velocity, acceleration;
printf("Enter the time in seconds \n");
scanf("%d",&amp;amp;sec);
printf("Enter the initial velocity \n");
scanf("%f", &amp;amp;initial_velocity);
printf("Enter the acceleration \n");
scanf("%f", &amp;amp;acceleration);
velocity = (initial_velocity + (acceleration * sec));
distance = (initial_velocity + (acceleration * (sec*sec)));\
printf("Total velocity is %f",velocity);
printf("Total distance travelled is  %f", distance);

}
```
 Enter the time in seconds 60 Enter the initial velocity 5 Enter the acceleration 7 Total velocity is 425.000000 Total distance travelled is 25205.000000

4. Accept inner and outer radius of a ring and print the perimeter and area of the ring.

(Hint: perimeter = 2 π (a+b) , area = π (a2-b2) )

```#include &amp;lt;stdio.h&amp;gt;
int main()
{
printf("Enter inner radius of ring: ");
printf("Enter outer radius of ring: ");
printf("Area of circle: %f \nPerimeter of circle: %f\n",area,perimeter);
}
```
 Enter inner radius of ring: 5 Enter outer radius of ring: 6 Area of circle: 191.539993 Perimeter of circle: 69.080002

5. Accept two numbers and print arithmetic and harmonic mean of the two numbers.

(Hint: AM= (a+b)/2 , HM = ab/(a+b) )

```#include &amp;lt;stdio.h&amp;gt;
void main()
{
int a,b;
float a_m,h_m;
printf("Enter two number A and B : \n");
scanf("%d%d",&amp;amp;a,&amp;amp;b);
a_m = (a+b) /2;
h_m = (a*b) / (a+b);
printf("Arithmetic Mean = %f \nHarmonic Mean = %f",a_m,h_m);
}
```
 Enter two number A and B : 2 6 Arithmetic Mean = 4.000000 Harmonic Mean = 1.000000

6. Accept three dimensions length (l), breadth(b) and height(h) of a cuboid and print surface area and volume.

(Hint : surface area=2(lb+lh+bh ), volume = lbh )

```#include &amp;lt;stdio.h&amp;gt;
void main()
{
float l, w, h;
float SA, V;

printf("Enter the Length, Width and Height of a Cuboid : \n");
scanf("%f %f %f",&amp;amp;l, &amp;amp;w, &amp;amp;h);
SA = 2 * (l * w + l * h + w * h);
V = l * w * h;
printf("\n The Surface Area of a Cuboid : %f\n",SA);
printf("\n The Volume of a Cuboid : %f\n",V);
}
```
 Enter the Length, Width and Height of a Cuboid : 2 4 6 The Surface Area of a Cuboid : 88.000000 The Volume of a Cuboid : 48.000000

7. Accept a character from the keyboard and display its previous and next character in order. Ex. If the character entered is ‘d’, display “The previous character is c”, “The next character is e”.

```#include &amp;lt;stdio.h&amp;gt;
int main()
{
char ch;
printf("Enter character:\t");
scanf("%c", &amp;amp;ch);
printf("You entered: %c\n", ch);
printf("Previous character: %c\n", ch - 1);
printf("Next character: %c\n", ch + 1);
}
```
 Enter character: f You entered: f Previous character: e Next character: g

8. Accept a character from the user and display its ASCII value.

```#include &amp;lt;stdio.h&amp;gt;
int main() {
char c;
printf("Enter a Character\n");
scanf("%c",&amp;amp;c);
printf("ASCII value of %c = %d",c,c);
return 0;
}
```
 Enter a Character A ASCII value of A = 65

If you like the post ‘C Programming Lab Course’, please share your feedback!