Chapter 1 - Let Us C
Temperature of a city in Fahrenheit degrees is input through the keyboard. Write a program to convert this temperature into Centigrade degrees.
#include <stdio.h>
int main(){
float deg;
printf("Enter the degree in Fahrenheits : ");
scanf("%f",°);
printf("The degree in Celcius is %f",(deg-32)*5/9);
return 0;
}
Step 1: Declare float variable `deg` for temperature.
Step 2: Take user input for temperature in Fahrenheit.
Step 3: Convert to Celsius using formula: (°F - 32) × 5/9.
Step 4: Print the converted temperature in Celsius.
Step 2: Take user input for temperature in Fahrenheit.
Step 3: Convert to Celsius using formula: (°F - 32) × 5/9.
Step 4: Print the converted temperature in Celsius.
The length and breadth of a rectangle and radius of a circle are input through the keyboard. Write a program to calculate the area and perimeter of the rectangle, and the area and circumference of the circle.
#include <stdio.h>
int main(){
float a,b;
printf("Enter the length of side of rectangle : ");
scanf("%f",&a);
printf("Enter the breadth of side of rectangle : ");
scanf("%f",&b);
printf("Perimeter of the rectangle = %f\nArea of the rectangle = %f",2*(a+b),a*b);
float r;
printf("Enter the radius of circle : ");
scanf("%f",&r);
printf("Circumference of the circle = %f\nArea of the circle = %f",2*3.14*r,3.14*r*r);
return 0;
}
Step 1: Declare float variables `a, b` for rectangle and `r` for circle.
Step 2: Take user input for rectangle's length and breadth.
Step 3: Calculate and print rectangle's:
• Perimeter = 2(length + breadth)
• Area = length × breadth
Step 4: Take user input for circle's radius.
Step 5: Calculate and print circle's:
• Circumference = 2 × π × radius
• Area = π × radius²
Step 2: Take user input for rectangle's length and breadth.
Step 3: Calculate and print rectangle's:
• Perimeter = 2(length + breadth)
• Area = length × breadth
Step 4: Take user input for circle's radius.
Step 5: Calculate and print circle's:
• Circumference = 2 × π × radius
• Area = π × radius²
Paper of size A0 has dimensions 1189 mm x 841 mm. Each subsequent size A(n) is defined as A(n-1) cut in half, parallel to its shorter sides. Thus, paper of size A1 would have dimensions 841 mm x 594 mm. Write a program to calculate and print paper sizes A0, A1, A2, … A8.
#include <stdio.h>
int main(){
int l = 841, b = 1189;
printf("Size of A0 = %dmm x %dmm\n",b,l);
printf("Size of A1 = %dmm x %dmm\n",l,b/2);
printf("Size of A2 = %dmm x %dmm\n",b/2,l/2);
printf("Size of A3 = %dmm x %dmm\n",l/2,b/4);
printf("Size of A4 = %dmm x %dmm\n",b/4,l/4);
printf("Size of A5 = %dmm x %dmm\n",l/4,b/8);
printf("Size of A6 = %dmm x %dmm\n",b/8,l/4);
printf("Size of A7 = %dmm x %dmm\n",l/4,b/16);
printf("Size of A8 = %dmm x %dmm\n",b/16,l/16);
return 0;
}
Step 1: Initialize variables for A0 size (841mm × 1189mm).
Step 2: Calculate subsequent sizes using the rule:
• Longer side becomes shorter side
• Shorter side becomes half of previous longer side
Step 3: Print dimensions for A0 through A8 using:
• Progressive division by 2 for dimensions
• Alternating length and breadth as paper is cut
Step 2: Calculate subsequent sizes using the rule:
• Longer side becomes shorter side
• Shorter side becomes half of previous longer side
Step 3: Print dimensions for A0 through A8 using:
• Progressive division by 2 for dimensions
• Alternating length and breadth as paper is cut
Comments