Let Us C Chapter 1 Exercise Solutions Part 1

Let Us C Chapter 1 Exercise Solutions Part 1

Part first of Let Us C Chapter 1 Exercise Solutions [H]. Get all the Let Us C Chapters Exercise Solutions. Chapter 1 Getting started.

[H] Write C programs for the following:

(a) 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>
void main()
{
int basic; //Basic Salary
float dearness; // Dearness Allowance,
float rent; //House rent Allowance,
float gross; //Gross Salary
clrscr();
printf("Enter Ramesh's Basic Salary= ");
scanf("%d",&basic_Salary);
dearness = basic_Salary*0.4;
rent =basic_Salary*0.2;
gross=basic_Salary-dearness-rent;
printf("Gross Salary of Ramesh is %f",gs);
getch();
}

=======================================
(b) 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>
void main()
{
float km,meter,feet,inch,centi;
/* km=kilometer distance || meter=meter distance || feet=feet distance || inch=inch distance
|| centi=centimeter distance */
clrscr();
printf("Enter distance between two cities : ");
scanf("%f",&km);
meter = km*1000; // 1km=1000 meters
feet = km*3280.8399; // 1km=3280.8399 feets
inch= km*39370.078; // 1km=39370.078 inches
centi= km*100000; // 1km=100000 meters
printf("\nDistance in Meters = %f",meter);
printf("\nDistance in Feet = %f",feet);
printf("\nDistance in Inches = %f",inch);
printf("\nDistance in Centimeters = %f,centi);
getch();
}

===================================================
(c) If the marks obtained by a student in five different subjects are input through the
keyboard, 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>
void main()
{

/* m1=Marks of 1st subjects and so on || agg=Aggregate marks || per=Percentage */
float m1,m2,m3,m4,m5,agg;
float per;
clrscr();
printf("Input marks of 5 subjects obtained by student:\n");
scanf("%f %f %f %f %f",&m1,&m2,&m3,&m4,&m5);
agg=m1+m2+m3+m4+m5;
per=agg*(100.0/500.0);
printf("Aggregate marks obtained by student = %d\n",agg);
printf("Percentage of student = %f%",per);
getch();
}

=================================================

(d) 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>
void main()
{
float faran; //faran =Fahrenheit Temperature,
float centi //centi=Centigrade Temperature
clrscr();
printf("Enter temperature of a city in Fahrenheit : ");
scanf("%f", &faran);
centi=(5.0/9.0)*(faran-32);
printf("The given temperature in Centigrade is %f",centi);
getch();
}

=========================================

(e) The length & breadth of a rectangle and radius of a circle are input through the keyboard.
Write a program to calculate the area & perimeter of the rectangle, and the area &
circumference of the circle.

#include<stdio.h>
#define pi 3.14 // PI as a constant
void main()
{
float rl,rb,ra,rp; // rl=Rect Length,rb=Rect Breadth,ra=Rect Area,rp=Rect Perimeter
float cr,ca,cc; // cr=Circle Radius,ca=Circle Area,cc=Circle Circumference
clrscr();
printf("Enter Length of Rectangle:");
scanf("%f",&rl);
printf("Enter Breadth of Rectangle:");
scanf("%f",&rb);
printf("Enter Radius of Cirlce:");
scanf("%f",&cr);
ra=rl*rb;
rp=2*(rl+rb);
ca=pi*cr*cr;
cc=2*pi*cr;
printf("\nArea of Rectangle = %f", ra);
printf("\nPerimeter of Rectangle = %f", rp);
printf("\nArea of Cirlce = %f", ca);
printf("\nCircumference of Circle = %f", cc);
getch();
}

====================================================

(f) Two numbers are input through the keyboard into two locations C and D. Write a program to
interchange the contents of C and D.


#include<stdio.h>
void main()
{
int a,b,c;
clrscr();
printf("Enter value of C : ");
scanf("%d",&a);
printf("Enter value of D : ");
scanf("%d",&b);
c=a;
a=b;
b=c;
printf("C = %d AND D = %d",a,b);
getch();
}

========================================================
(g) If a five-digit number is input through the keyboard, write a program to calculate the sum
of its digits? (Hint: Use the modulus operator ‘%’)

#include<stdio.h>
void main()
{
int num,sum,n1,n2,n3,n4,n5;
clrscr();
printf("Enter any five digit number : ");
scanf("%d",&num);
n1 = num%10; // To Extract The Last Digit
num /= 10; // To Delete The Last Digit
n2 = num%10;
num /= 10;
n3 = num%10;
num /= 10;
n4 = num%10;
num /=10;
n5 = num%10;
num /= 10;
sum=n1+n2+n3+n4+n5;
printf("\nSum of digits of given number is %d",sum);
getch();
}

==============================================

NOTE: 

 If you find any error in the above codes please notify in the comment section. If you have a more efficient method for any of the program please post in the comments and we will add it to the post with Your name    - Taha 

Let Us C Chapter 1 Exercise Solutions Part 2>>>>

Incoming search terms:

  • exercise of chap 1 of let us C Solutions part1
  • solution of c program(a) 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

One Response to Let Us C Chapter 1 Exercise Solutions Part 1

  1. […] Let Us C Chapter 1 Exercise Solutions Part 1 >>> […]

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>