Chapter 1: Getting Started – Let Us C Solutions

In the first chapter, the Let Us C covered all the basic things we need to get started in the journey of learning C Programming. Now, let’s have a look at the solutions of the exercise of the first chapter, Getting Started from Let Us C.

[A] Which of the following are invalid C constants and why?

‘3.15’35,5503.25e2
2e-3‘eLearning’“show”
‘Quest’234 6 5 2

Answer:

Reason
‘3.15’‘eLearning’‘Quest’Single quotes are used for single-character literals
“35,550”“2^3”“4 6 5 2”use of space and comma is prohibited and you can’t use exponent in the declaration

[B] Which of the following are invalid variable names and why?

B’dayint$hello
#HASHdot.number
totalArea_main()temp_in_Deg
total%1ststack-queue
variable name%name%salary

Answer:

Invalid VariablesReason
B’day $hello #HASH _main() total% %name% stack-queue dot.Special Characters are not accepted as name of variables
variable name 1stSpaces and variables beginning with numbers are not allowed
intIdentifiers can’t be used as variables

[C] State whether the following statements are True or False:

(a) C language has been developed by Dennis Ritchie

Answer: True

(b) Operating systems like Windows, UNIX, Linux and Android are written in C.

Answer: True

(c) C language programs can easily interact with hardware of a PC/Laptop.

Answer: True

(d) A real constant in C can be expressed in both Fractional and Exponential form

Answer: True

(e) A character variable can at a time store only one character.

Answer: True

(f) The maximum value that an integer constant can have varies
from one compiler to another.

Answer: True

(g) Usually, all C statements are entered in small case letters.

Answer: True

(h) Spaces may be inserted between two words in a C statement.

Answer: True

(i) Spaces cannot be present within a variable name.

Answer: True

(j) C programs are converted into machine language with the
help of a program called Editor.

Answer: False

(k) Most development environments provide an Editor to type a C
program and a Compiler to convert it into machine language.

Answer: True

(l) int, char, float, real, integer, character, char, main, printf
and scanf all are keywords.

Answer: False

[D] Match the Following:

\nLiteral
3.145Statement Terminator
-6513Character Constant
‘D’Escape Sequence
4.25e-3Input Function
main()Function
%f, %d, %cInteger Constant
;Address of Operator
ConstantOutput Function
VariableFormat Specifier
&Exponential Form
printf()Real Constant
scanf()Identifier

Answer:

\nEscape sequence
3.145Real constant
-6513Integer constant
’D’Character constant
4.25e-3Exponential form
main( )Function
%f, %d, %cFormat specifier
;Statement terminator
ConstantLiteral
VariableIdentifier
&Address of operator
printf( )Output function
scanf( )Input function

[E] Point out errors, if any, in the following programs:

(a)

int main()
{
int a, float b, int c;
a=25; b=3.24; c= a + b * b - 35;
}

Answer: It has no errors.

(b)

/* Calculation of average 
/* Author: Sanjay */
/* Place - Whispering Bytes */
*/
#include<stdio.h>
int main()
{
int a = 35; float b = 3.24;
printf("%d %f %d", a, b + 1.5, 235);
}

Answer: It has no errors.

(c)

#include<stdio.h>
int main()
{
int a, b, c;
scanf("%d %d %d", a, b, c);
}

Answer: Variable Address Specifier or & symbol is missing from the scanf() statement.

(d)

#include <stdio.h>
int main()
{
int m1, m2, m3
printf("Enter values of marks in 3 subjects")
scanf("%d %d %d", &m1, &m2, &m3)
printf("You entered %d %d %d", m1, m2, m3);
}

Answer: Statement terminator or “;” symbol is missing

[F] Attempt 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

Program:

#include <stdio.h>
int main()
{
float basicPay, da, hra, grossPay;
printf("\nEnter Basic Salary of Ramesh: ");
scanf("%f", &basicPay);
da = 0.4 * basicPay;
hra = 0.2 * basicPay;
grossPay = basicPay + da + hra;
printf("Basic Salary of Ramesh: %f\n ", basicPay);
printf("DA of Ramesh: %f\n ", da);
printf("HRA of Ramesh: %f\n ", hra);
printf("Gross Salary of Ramesh: %f\n", grossPay);
return 0 ;
}

(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.

Program:

#include<stdio.h>
int main()
{
float km, m, cm, ft, inch ;
printf("Enter the distance in Km: ");
scanf("%f", &km);
m = km * 1000;
cm = m * 100;
inch = cm / 2.54;
ft = inch / 12;
printf("Distance in meters = %f\n", m);
printf("Distance in centimeter = %f\n", cm);
printf("Distance in feet = %f\n", ft);
printf("Distance in inches = %f\n", inch);
return 0;
}

(c) 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.

Problems:

# include <stdio.h>
int main()
{
int m1, m2, m3, m4, m5, aggr;
float per;
printf("\nEnter marks in 5 subjects: ");
scanf("%d %d %d %d %d", &m1, &m2, &m3, &m4, &m5);
aggr = m1 + m2 + m3 + m4 + m5;
per = aggr / 5;
printf("Aggregate Marks = %d\n", aggr) ;
printf("Percentage Marks = %f\n", per) ;
return 0;
}

(d) Temperature of a city in Fahrenheit degrees is input through
the keyboard. Write a program to convert this temperature
into Centigrade degrees.

Program:

#include<stdio.h>
int main()
{
float fr, cent;
printf("\nEnter the temperature (F): ");
scanf("%f", &fr);
cent = 5.0 / 9.0 * ( fr - 32 );
printf("Temperature in centigrade = %f\n", cent);
return 0;
}

(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

Program:

# include <stdio.h>
int main( )
{
int l, b, r, area1, perimeter;
float area2, circum;
printf("\nEnter Length & Breadth of Rectangle: ");
scanf("%d %d", &l, &b);
area1 = l * b;
perimeter = 2 * l + 2 * b;
printf("Area of Rectangle = %d\n", area1);
printf("Perimeter of Rectangle = %d\n", perimeter);
printf("\n\nEnter Radius of circle: ");
scanf("%d", &r );
area2 = 3.14 * r * r; 
circum = 2 * 3.14 * r; 
printf("Area of Circle = %f\n", area2);
printf("Circumference of Circle = %f\n", circum);
return 0;
}

(f) 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. Write a program to calculate and print
paper sizes A0, A1, A2, … A8.

Program:

# include <stdio.h>
int main( )
{
int a0ht, a0wd ;
int a1ht, a1wd, a2ht, a2wd ;
int a3ht, a3wd, a4ht, a4wd ;
int a5ht, a5wd, a6ht, a6wd ;
int a7ht, a7wd, a8ht, a8wd ;
a0ht = 1189 ;
a0wd = 841 ;
printf ( "Size of A0 paper Height = %d Width = %d\n", a0ht, a0wd ) ;
a1ht = a0wd ;
a1wd = a0ht / 2 ;
printf ( "Size of A1 paper Height = %d Width = %d\n", a1ht, a1wd ) ;
a2ht = a1wd ;
a2wd = a1ht / 2 ;
printf ( "Size of A2 paper Height = %d Width = %d\n", a2ht, a2wd ) ;
a3ht = a2wd ;
a3wd = a2ht / 2 ;
printf ( "Size of A3 paper Height = %d Width = %d\n", a3ht, a3wd ) ;
a4ht = a3wd ;
a4wd = a3ht / 2 ;
printf ( "Size of A4 paper Height = %d Width = %d\n", a4ht, a4wd ) ;
a5ht = a4wd ;
a5wd = a4ht / 2 ;
printf ( "Size of A5 paper Height = %d Width = %d\n", a5ht, a5wd ) ;
a6ht = a5wd ;
a6wd = a5ht / 2 ;
printf ( "Size of A6 paper Height = %d Width = %d\n", a6ht, a6wd ) ;
a7ht = a6wd ;
a7wd = a6ht / 2 ;
printf ( "Size of A7 paper Height = %d Width = %d\n", a7ht, a7wd ) ;
a8ht = a7wd ;
a8wd = a7ht / 2 ;
printf ( "Size of A8 paper Height = %d Width = %d\n", a8ht, a8wd ) ;
return 0 ;
}

These were the solutions of Chapter 1: Getting Started of Let Us C Book by Yashvant Kanetkar.

PreviousNext
Let Us C Solutions: IndexChapter 2: C Instruction – Let Us C Solutions

Leave a Reply

Your email address will not be published.