Posts

Showing posts from February, 2024

[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; }

[Tutorial 7] 5.Which of the following are invalid constants? Why?

123.456                     0996 0x10.5                     -12E-12 0X0G1                     07777 0001                          1234uL 0xFFFF                   1.2Fe-7 123L                           15,000 0Xab05                   1.234L 0L -597.25              197u 123.5e2                   1 00U .0001                        0XABCDEFL +12                            0xabcu 98.6F                        +123 98.7U 17777s

[Tutorial 7] 4.Which of the following are invalid variable names? Why?

1. Int char 6_05 2. Calloc Xx alpha_beta_routine 3. floating _1312 z 4. ReInitialize _ A$

[Tutorial 7] 3. What output might you expect from the following program?

#include <stdio.h> int main (void) {       int answer, result;     answer = 100;     result = answer - 10;     printf ( "The result is %i\n" , result + 5); return 0; }

[Tutorial 7] 2.Identify the syntactic errors in the following program. Then type in and run the corrected program to ensure you have correctly identified all the mistakes.

#include <stdio.h> int main (Void) ( INT sum; /* COMPUTE RESULT sum = 25 + 37 – 19 /* DISPLAY RESULTS // printf ( "The answer is %i\n" sum); return 0; }

[Tutorial 7] 1.Write a program that subtracts the value 15 from 87 and displays the result, together with an appropriate message, at the terminal.

#include <stdio.h> int main(void) { int sum; /* COMPUTE RESULT */ sum = 87 - 15; /* DISPLAY RESULTS */ printf ( "The answer is %i \n" , sum); return 0; }

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

#include <stdio.h> int main (void) {      printf ( "Testing..." );      printf ( "....1" );      printf ( "...2" );      printf ( "..3" );      printf ( "\n" ); return 0; } OUTPUT => Testing.......1...2..3 This C program defines a main() function that sequentially prints out the strings "Testing...", "....1", "...2", and "..3" each on a separate line using the printf() function. It concludes with a newline character. The program then returns 0, indicating successful execution to the operating system.

[Tutorial 6 ] 2. Write a program that prints the following text at the terminal.

i) * * * * * * * * * * * * * * * * * * * * * #include <stdio.h> int main( void ) { int row,column; for (row=1;row<=6;row++) { for( column=1;column<=row;column++) { printf( "*" ); } printf( "\n" ); } return 0; } This C program prints a pattern resembling a right triangle with asterisks, where the number of asterisks in each row increases from 1 in the first row to 6 in the last row. It achieves this using nested loops: the outer loop controls the number of rows, and the inner loop determines the number of asterisks to print in each row. After printing the required number of asterisks in each row, a newline character is printed to move to the next row. Thus, the result is a right triangle pattern made of asterisks.

[Tutorial 6 ] 1. Write a program that prints the following text at the terminal.

#include <stdio.h> int main ( void ) { printf ( "* In C, lowercase letters are significant. \n" ); printf ( "* main is where program execution begins.\n" ); printf ( "* Opening and closing braces enclose program statements in a routine.\n" ); printf ( "* All program statements must be terminated by a semicolon.\n" ); return 0; }