Skip to content

Instantly share code, notes, and snippets.

@RohitSingh2k
Created June 11, 2021 07:38
Show Gist options
  • Save RohitSingh2k/fa1ba963ddc4236ec492e1511036e257 to your computer and use it in GitHub Desktop.
Save RohitSingh2k/fa1ba963ddc4236ec492e1511036e257 to your computer and use it in GitHub Desktop.
Here you will find all solution of Let Us C book.
/*
Author : Rohit Singh
Purpose: To implement all exercise of let us c book.
*/
/*
######################################### Let us C Chapter 1 Solution #########################################
_______________________________________________________________________________________________________________
*/
/*
Ramesh’s basic salary is input through the keyboard. His dearness
allowance is 40% of basic salary, and house rent allowance is 20% of
basic salary. Write a program to calculate his gross salary.
*/
#include<stdio.h>
int main()
{
int basic_salary;
printf("Enter Ramesh's Basic Salary : ");
scanf("%d",&basic_salary);
int dearness_allowance = ( basic_salary * 40 ) / 100;
int house_rent = ( basic_salary * 20 ) / 100;
int gross_salary = basic_salary + dearness_allowance + house_rent;
printf("Ramesh's Gross salary is %d\n",gross_salary);
return 0;
}
/*
The distance between two cities (in km.) is input through the
keyboard. Write a program to convert and print this distance in
meters, feet, inches and centimeters.
*/
#include<stdio.h>
int main()
{
int distance;
printf("Enter distance between two cities in km : ");
scanf("%d",&distance);
printf("Distance ( meter ) = %d\n",distance * 1000);
printf("Distance ( foot ) = %.2f\n",distance * 3280.84);
printf("Distance ( inches ) = %.2f\n",distance * 39370.1);
printf("Distance ( centimeters ) = %.2f\n",distance * 100000.054);
return 0;
}
/*
If the marks obtained by a student in five different subjects are
input through the keyboard, write a program to find out the
aggregate marks and percentage marks obtained by the student.
Assume that the maximum marks that can be obtained by a student
in each subject is 100.
*/
#include<stdio.h>
int main()
{
int marks[5],i;
int sum = 0;
for(i = 0; i < 5; i++ )
{
printf("Enter the marks obtain in %d subject : ",i+1);
scanf("%d",&marks[i]);
sum += marks[i];
}
printf("Total marks obtain = %d\n",sum);
int percentage = (sum * 100) / 500;
printf("Percentage obtained = %d\n",percentage);
return 0;
}
/*
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(int argc, char const *argv[])
{
int fahrenheit;
printf("Enter city's tempreture in fahrenheit :");
scanf("%d",&fahrenheit);
float centigrade = ( fahrenheit - 32 ) * ( 5.0 / 9.0 );
printf("City's tempreture is %.1f centigrade",centigrade);
return 0;
}
/*
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>
#define PI 3.14
int main(int argc, char const *argv[])
{
int length,breath;
float radius;
printf("Enter the length of rectangle : ");
scanf("%d",&length);
printf("Enter the breath of rectangle : ");
scanf("%d",&breath);
printf("Enter the radius of circle : ");
scanf("%f",&radius);
int area = length * breath;
int perimeter = 2 * length * breath;
printf("Area of the rectangle is %d & perimeter of the rectangle is %d\n",area,perimeter);
printf("Area of the circle is %.2f & circumference is %.2f\n",(PI * radius * radius),( 2 * PI * radius));
return 0;
}
/*
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 argc, char const *argv[])
{
int i, width=841, height=1189, temp;
for(i = 0; i < 9; i++)
{
printf("\n A%d: %d x %d", i, width, height);
temp = height;
height = width;
width = temp / 2;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment