Posts

[Tutorial 7] 15.The figure gives a rough sketch of a running track. It includes a rectangular shape and two semi-circles. The length of the rectangular part is 67m and breadth is 21m.Calculate the distance of the running track.

Image
  #include <stdio.h> #define PI 3.142 int main()  { float distance_rectangular, distance_semi_circles, total_distance; float  length_rectangular = 67.0;  float  breadth_rectangular = 21.0;  distance_rectangular = 2 * length_rectangular ; distance_semi_circles = 2 * PI * (breadth_rectangular/2); total_distance = distance_rectangular +distance_semi_circles; /* Display the total distance*/ printf( "The distance of the running track is %.2f meters\n" , total_distance); return 0; }

[Tutorial 7] 14.Write a program that converts inches to centimeters. For example, if the user enters 16.9 for a Length in inches, the output would be 42.926cm. (Hint: 1 inch = 2.54 centimeters.)

#include <stdio.h> int main() { float inches, centimeters; /*Input length in inches from the user*/      printf( "Enter length in inches: " );      scanf( "%f" , &inches); /*Convert inches to centimeters*/      centimeters = inches * 2.54; /* Display the result */      printf( "%.2f inches is equal to %.3f centimeters\n" , inches, centimeters); return 0; }

[Tutorial 7] 13.Enter the name, height, weight and gender of a person and calculate his/her BMI in Kg. BMI = weight/ height2

#include <stdio.h> int main() { char name[50], gender; float height, weight, bmi; /* Input data from user */      printf( "Enter name: " );      scanf( "%s" , name);      printf( "Enter height in meters: " );      scanf( "%f" , &height);      printf( "Enter weight in kilograms: " );      scanf( "%f" , &weight);      printf( "Enter gender (M/F): " );      scanf( " %c" , &gender);  /* Calculate BMI*/      bmi = weight / (height * height); /* Display the result*/      printf( "\n%s's BMI: %.2f\n" , name, bmi); return 0; }

[Tutorial 7] 12.Find the cost of 5 items if the unit price is 10.50 Rupees.

#include <stdio.h> int main()  {      float unit_price = 10.50;      int num_items = 5;      float cost; /* Calculate the cost*/      cost = unit_price * num_items; /* Display the result*/      printf( "The cost of %d items is %.2f Rupees\n" , num_items, cost); return 0; }

[Tutorial 7] 11.Find the value of y using y = 3.5x+5 at x = 5.23.

#include <stdio.h> int main() { float x, y; /* Given value of x*/      x = 5.23; /*Calculate y using the equation y = 3.5x + 5*/      y = 3.5 * x + 5; /*Display the result*/      printf( "When x = %.2f, the value of y is %.2f\n" , x, y); return 0; }

[Tutorial 7] 10.Convert the given temperature in Celsius to Fahrenheit. T(°F) = T(°C) × 1.8 + 32

#include <stdio.h> int main() { float celsius, fahrenheit; /* Input temperature in Celsius from the user*/      printf( "Enter temperature in Celsius: " );      scanf( "%f" , &celsius); /* Convert Celsius to Fahrenheit*/      fahrenheit = celsius * 1.8 + 32; /* Display the temperature in Fahrenheit*/      printf( "%.2f Celsius is equal to %.2f Fahrenheit\n" , celsius, fahrenheit); return 0; }

[Tutorial 7] 9.Calculate average marks of 4 subjects which, entered separately.

#include <stdio.h> int main() { float subject1, subject2, subject3, subject4, average;      /* Input marks of each subject from the user*/      printf( "Enter marks of subject 1: " );      scanf( "%f" , &subject1);      printf( "Enter marks of subject 2: " );      scanf( "%f" , &subject2);      printf( "Enter marks of subject 3: " );      scanf( "%f" , &subject3);      printf( "Enter marks of subject 4: " );      scanf( "%f" , &subject4); /* Calculate average marks*/      average = (subject1 + subject2 + subject3 + subject4) / 4; /* Display the average marks*/      printf( "The average marks of the four subjects is: %.2f\n" , average); return 0; }

[Tutorial 7] 8.Calculate the volume of a cylinder. PI * r2 h

#include <stdio.h> #define PI 3.14159 int main()  { float radius, height, volume; /* Input radius and height from the user*/      printf( "Enter the radius of the cylinder: " );      scanf( "%f" , &radius);      printf( "Enter the height of the cylinder: " );      scanf( "%f" , &height); /* Calculate volume*/      volume = PI * radius * radius * height; /* Display the volume*/      printf( "The volume of the cylinder is: %.2f cubic units\n" , volume); return 0; }

[Tutorial 7] 7.Convert given value in Meter to centimeter.

#include <stdio.h> int main() {      double meters, centimeters;      /* Input length in meters*/      printf( "Enter length in meters: " );      scanf( "%lf" , &meters);      /* Convert meters to centimeters*/      centimeters = meters * 100;      /* Display the result*/      printf( "%.2f meters is equal to %.2f centimeters.\n" , meters, centimeters); return 0; }

[Tutorial 7] 6.What output would you expect from the following program?

#include <stdio.h> int main ( void ) { char c, d; c = 'd'; d = c; printf ( "d = %c\n" , d); return 0; }