SlideShare a Scribd company logo
2
Most read
3
Most read
7
Most read
CHAPTER 2: Constants, Variables, and Data Types
REVIEW QUESTIONS
STATE WHETHER THE FOLLOWING STATEMENTS ARE TRUE OR
FALSE:
(a) Any valid printable ANSII character can be used in an identifier. ( False )
(b) All variables must be given a type when they are declared. ( True )
(c) Declarations can appear anywhere in a program. ( False )
(d) ANSI C treats the variable name and Name to be same. ( False )
(e) The underscore can be used anywhere in an identifier. ( True )
(f) The keyword void is a data type in C. ( True )
(g) Floating point data constants, by default, denote float type values. ( False )
(h) Like variables, constants have a type. ( True )
(i) Character constants are coded using double quotes. (False )
(j) Initialization is the process of assigning a value to a variable at the time of
declaration. ( true )
(k) All static variables are automatically initialized to zero. ( True )
(l) The scanf function can be used to read only one value at a time. ( False )
Fill in the blanks with appropriate words:
(a)The keyword ……………..can be used to create a data type identifier.
Answer: int
(b) …………… is the largest value that an unsigned short int type variable can
store.
Answer: 255
(c) A global variable is also known as …………….variable.
Answer: external
(d) A variable can be made constant by declaring it with the qualifier …………….
At the time of initialization.
Answer: constant
Question: What are trigraph characters? How are they useful?
Answer:
Trigraph characters is one kinds of character which consists of three characters (
Two question marks and followed by another ).
Some keyboard does not support some characters. But we can use them by trigraph
characters. If a keyboard does not support square brackets, we can still use them in
a program using the trigraph ??( and ??) .
Question: Describe the four basic data types. How could we extend the range of
values they represent?
Answer:
The basic four data types are:
(1) Char
(2) Int
(3) Float
(4) Void
We cannot extend the range of character.
We could extend the range of integer by using long before integer.
We can extend the range of float by using double. To extend the precision further
we may use long double.
Question: What is an unsigned integer constant? What is the significant of
declaring a constant unsigned?
Answer:
The integer constant which does not take any + or – sign before it is called an
unsigned integer constant.
We can take the value double using an unsigned integer constant. For example, a
signed integer constant have a value between -32768 to +32767, but an unsigned
integer constant takes the value between 0 to 65535.
Question: Describe the characteristics and purpose of escape sequence characters.
Answer:
C supports some special back slash character constants, that are used in output
function. This characters are known as escape sequence characters. For example,
the symbol “n” stands for new line character.
Characteristics :
(1) They acts as a single character.
(2) Each escape sequence character consists of two characters.
(3) The first character must be a back slash .
Purpose:
(1) In a program we used it for new line.
(2)In a program we used it for horizontal tab.
Question: What is a variable and what is meant by “value” of a variable?
Answer:
A variable is a data name that may used to store a data value. Like constants that
remains unchanged during the execution a program.
The meant of value it is a variable name and it can take any value like character,
int, float and double.
Question: How do variables and symbolic names differ?
Answer:
A variable may be used to store data value. A variable may take different values at
different times during execution of a program. Variables has need to declare at the
beginning of the body but after the main.
Symbolic names is a unique constants. This constants may appear in a number of
place in the program. Symbolic names has need to define at the beginning of a
program.
Question: State the difference between the declaration of a variable and the
definition of a symbolic name?
Answer:
Variables has need to declare at the beginning of the body but after the main. The
syntax for declaring a variable is as follow:
Data-type v1,v2,……..vn;
v1, v2,……..vn are the names of variables. For example, valid declarations are
int count;
int number,total;
float ratio;
Symbolic names has need to define at the beginning of a program. A symbolic
name constants is defined as follows:
#define symbolic-name value of constant
Valid example of constant definations are:
#define STRENGTH 100
#define PASS MARK 5
Question: What is initialization? Why it is important?
Answer:
The process of giving initial values to variables is called initialization. Some
examples are
int final_value =100;
char yes =’x’;
double balance =75.84;
C permits the initialization of more then one variable using multiple assignment
operators.For example the statements
p=q=s=0;
x=y=z=MAX;
are valid.
Question: What are the qualifiers that an int can have at a time?
Answer:
A signed int can take a value between -32768 to 32767 and an unsigned int can
take a value 0 to 65535.
Question: Describe the purpose of the qualifiers constant and volatile.
Answer:
We may like the value of certain variables to remain constant during
the excution of a program. We can achieve this by declaring the variable with the
qualifier constant at the time of initialization. Example:
const int class_size=40;
ANSI standard defines another qualifier volatile that could be used to tell
explicitly the complier that a variables value may be changed at any time by some
external sources ( from outside the program). For example:
volatile int date;
Question: When dealing with very small or very large numbers, what steps would
you like you take to improve the accurancy of the calculation?
Answer:
When we are dealing with a very short number we can improve the accurancy of
calculation by using a keyword short before the keyword. Example short int.
When we are dealing with a very large number we can improve the accurancy of
calculation by using a keyword long before the keyword. Example long int.
Question: Which of the following are invalid constants and why?
0.0001
Answer: (valid)
5x1.5
Answer: (Invalid)
Reason: Exponent must be an integer.
99999
Answer: Valid
Reason: Long integer.
+100
Answer: ( valid)
75.45E-2
Answer: ( Valid )
-45.6
Answer: ( Valid )
“15.75”
Answer: ( Invalid )
Reason: “” sign is not permitted.
-1.79e+4
Answer: (valid)
0.00001234
Answer: ( Valid )
Question: Which of the following are invalid variable and why?
Minimum
Answer: ( valid )
First.name
Answer: ( Invalid )
Reason:. Sign is not permitted.
N1+n2
Answer: ( Invalid )
Reason: + sign is not permitted.
&name
Answer: ( Invalid )
Reason: & is not permitted.
Doubles
Answer: ( Valid )
Reason: Keyword may be a part of variable name.
3rd_row
Answer: ( Invalid )
Reason: First character must be a letter or underscore.
n$
Answer: ( Invalid )
Reason: Dollar sign is not permitted.
Row1 ( Valid )
Float
Answer: ( Invalid )
Reason: float is a keyword.
Sum Total
Answer: ( Invalid )
Reason: White space is not permitted.
Row Total
Answer: ( Invalid )
Reason: White space is not permitted.
Column total
Answer: ( Invalid )
Reason: White space is not permitted.
Question: Find errors, if any, in the following declaration statements.
{
Int x;
float letter,DIGIT;
double=p,q;
exponent alpha,beta;
m,n.z:INTEGER
short char c;
long int m;count;
long float temp;
getch();
}
Error1: intx should have a type.
Error2: Line number 6, expression syntax.
Error3: Line number 7, Declaration should be properly.
Error4:Line number 9, Unreachable code.
Problem no 2.1: Write a program to determine and print the sum of the following
harmonic series for a given value of n:
1+1/2+1/3+………………+1/n
Solve:
#include<stdio.h>
#include<conio.h>
Void main()
{
int n;
float I, sum, t;
clrscr();
printf(“1+1/2+1/3+……………+1/nn”);
printf(“Enter the value of nn”);
scanf(“%d”,&n);
sum=0;
for(i=1;i<=n;i++)
{
t=1/i;
sum=sum+t;
}
printf(“%f”,sum);
getch();
}
Output:
1+1/2+1/3+………….+1/n
Enter the value of n
4
2.083333
The value of n should be given interactively through the terminal.
Problem no 2.2: Write a program to read the price of an item in decimal form (
like 15.95 ) and print the output in paisa ( like 1595 paisa) .
Solve:
#include<stdio.h>
#include<conio.h>
void main()
{
int b;
float a;
a=15.95;
clrscr();
b=100*a;
printf("%d",b);
getch();
}
Output:
1595
Problem no 2.3: Write a program that’s prints the even numbers from 1 to 100.
#include<stdio.h>
#include<conio.h>
void main()
{
int i;
for(i=1;i<=100;i++)
{
if(i%2==0)
printf(" %d",i);
}
getch();
}
Output
2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46
48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90
92 94 96 98 100
Problem no 2.4: Write a program that request two float type numbers from the
users and then divides the first number by the second and display the result along
with the numbers.
Solve:
#include<stdio.h>
#include<conio.h>
void main()
{
float number1, number2, number3;
clrscr();
printf("Enter the value of number1 and number2n");
scanf("%f %f",&number1,&number2);
number3=number1/number2;
printf("%f/%f=%f",number1,number2,number3);
getch();
Output:
Enter the value of number1 and number2
15.5
6.6
15.5/6,6=2.348484
Problem no 2.5: The price of one kg of rice is Rs. 16.75 and one kg of sugar is Rs.
15. Write a program to get these values from the user and display the prices as
follows:
***LIST OF ITEMS***
Item Price
Rice Rs 16.75
Sugar Rs 15.00
Solve:
#include<stdio.h>
#include<conio.h>
void main ()
{
float Rice,Sugar;
Rice=16.75;
Sugar=15.00;
clrscr();
printf("***LIST OF ITEMS***n");
printf("Item tPricen");
printf("RicetRs%.2fn",Rice);
printf("SugartRs%.2fn",Sugar);
getch();
}
Output:
***LIST OF ITEMS***
Item Price
Rice Rs16.75
Question: Identify syntax errors in the following program. After correcting, what
output would you expect when you execute it.
#include<stdio.h>
#include<conio.h>
#define PI 3.14159
void main()
{
int R,C;
float perimeter;
float area;
C=PI;
R=5;
perimeter=2.0*C*R;
Area = C*R*R;
printf("%f", "%d",&perimeter,&area)
}
Errors:
Cpp 10: Undefined symbol Area.
Cpp 12:statement missing,in function{}
Cpp12: compound statement missing.
Solve:
#include<stdio.h>
#include<conio.h>
#define PI 3.14159
void main()
{
int R,C;
float perimeter,Area;
C=PI;
R=5;
perimeter=2.0*C*R;
Area = C*R*R;
printf("%f %f",perimeter,Area);
getch();
}
Reference:
http://hstuadmission.blogspot.com/2010/12/solution-programming-in-ansi-c-
chapter.html

More Related Content

What's hot (20)

PDF
Chapter 5 Balagurusamy Programming ANSI in c
BUBT
 
PDF
Chapter 4 : Balagurusamy Programming ANSI in C
BUBT
 
PDF
Chapter 6 Balagurusamy Programming ANSI in c
BUBT
 
RTF
Ansi c
dayaramjatt001
 
PPTX
Function in C program
Nurul Zakiah Zamri Tan
 
PDF
Chapter 5 exercises Balagurusamy Programming ANSI in c
BUBT
 
DOCX
Chapter 8 c solution
Azhar Javed
 
PPTX
Typecasting in c
Tushar Shende
 
PPTX
C if else
Ritwik Das
 
DOCX
Let us C (by yashvant Kanetkar) chapter 3 Solution
Hazrat Bilal
 
PPTX
Recursive Function
Harsh Pathak
 
PPTX
Storage class in c
kash95
 
PDF
The solution manual of programming in ansi by Robin
Shariful Haque Robin
 
PPT
Multidimensional array in C
Smit Parikh
 
PPT
CPU INPUT OUTPUT
Aditya Vaishampayan
 
PPTX
Unit 3. Input and Output
Ashim Lamichhane
 
PPT
Class and object in C++
rprajat007
 
PDF
Let us c(by yashwant kanetkar) chapter 2 solution
rohit kumar
 
DOCX
C Programming
Sumant Diwakar
 
PPTX
Call by value
Dharani G
 
Chapter 5 Balagurusamy Programming ANSI in c
BUBT
 
Chapter 4 : Balagurusamy Programming ANSI in C
BUBT
 
Chapter 6 Balagurusamy Programming ANSI in c
BUBT
 
Function in C program
Nurul Zakiah Zamri Tan
 
Chapter 5 exercises Balagurusamy Programming ANSI in c
BUBT
 
Chapter 8 c solution
Azhar Javed
 
Typecasting in c
Tushar Shende
 
C if else
Ritwik Das
 
Let us C (by yashvant Kanetkar) chapter 3 Solution
Hazrat Bilal
 
Recursive Function
Harsh Pathak
 
Storage class in c
kash95
 
The solution manual of programming in ansi by Robin
Shariful Haque Robin
 
Multidimensional array in C
Smit Parikh
 
CPU INPUT OUTPUT
Aditya Vaishampayan
 
Unit 3. Input and Output
Ashim Lamichhane
 
Class and object in C++
rprajat007
 
Let us c(by yashwant kanetkar) chapter 2 solution
rohit kumar
 
C Programming
Sumant Diwakar
 
Call by value
Dharani G
 

Similar to Chapter 2 : Balagurusamy_ Programming ANsI in C (20)

PDF
C programing Tutorial
Mahira Banu
 
DOCX
Compiler lab final report writing
Umme habiba
 
PDF
PSPC--UNIT-2.pdf
ArshiniGubbala3
 
PPTX
Data Types, Variables, and Constants in C# Programming
Sherwin Banaag Sapin
 
PPTX
C
PRADEEPA R
 
PPT
C tutorial
Anurag Sukhija
 
PPTX
PROGRAMMING IN C - Inroduction.pptx
Nithya K
 
PPT
Java: Primitive Data Types
Tareq Hasan
 
PDF
Introduction
Komal Pardeshi
 
PPTX
presentation_data_types_and_operators_1513499834_241350.pptx
KrishanPalSingh39
 
PPTX
Get Fast C++ Homework Help
C++ Homework Help
 
PPTX
the refernce of programming C notes ppt.pptx
AnkitaVerma776806
 
PPTX
Introduction to C Programming
Aniket Patne
 
PPTX
Claguage 110226222227-phpapp02
CIMAP
 
PPTX
Data Types and Variables In C Programming
Kamal Acharya
 
PPTX
Module 1:Introduction
nikshaikh786
 
PPT
Unit i intro-operators
HINAPARVEENAlXC
 
DOC
Visual c sharp
Palm Palm Nguyễn
 
PPTX
Structured Languages
Mufaddal Nullwala
 
PPTX
Python
Sangita Panchal
 
C programing Tutorial
Mahira Banu
 
Compiler lab final report writing
Umme habiba
 
PSPC--UNIT-2.pdf
ArshiniGubbala3
 
Data Types, Variables, and Constants in C# Programming
Sherwin Banaag Sapin
 
C tutorial
Anurag Sukhija
 
PROGRAMMING IN C - Inroduction.pptx
Nithya K
 
Java: Primitive Data Types
Tareq Hasan
 
Introduction
Komal Pardeshi
 
presentation_data_types_and_operators_1513499834_241350.pptx
KrishanPalSingh39
 
Get Fast C++ Homework Help
C++ Homework Help
 
the refernce of programming C notes ppt.pptx
AnkitaVerma776806
 
Introduction to C Programming
Aniket Patne
 
Claguage 110226222227-phpapp02
CIMAP
 
Data Types and Variables In C Programming
Kamal Acharya
 
Module 1:Introduction
nikshaikh786
 
Unit i intro-operators
HINAPARVEENAlXC
 
Visual c sharp
Palm Palm Nguyễn
 
Structured Languages
Mufaddal Nullwala
 
Ad

More from BUBT (12)

DOCX
Lab report cover page
BUBT
 
DOCX
Project report title cover page
BUBT
 
PPTX
Implementation Of GSM Based Fire Alarm and Protection System
BUBT
 
PPTX
Student Attendance
BUBT
 
PPTX
Reasoning for Artificial Intelligence Expert
BUBT
 
DOCX
Auto Room Lighting and Door lock Report
BUBT
 
PPTX
Auto Room Lighting System
BUBT
 
PPTX
Doorlock
BUBT
 
PPTX
Ultra Dense Netwok
BUBT
 
PPTX
Bangladesh University of Business and Technology
BUBT
 
PPTX
Art Gallery Management System
BUBT
 
PPTX
Shop management system
BUBT
 
Lab report cover page
BUBT
 
Project report title cover page
BUBT
 
Implementation Of GSM Based Fire Alarm and Protection System
BUBT
 
Student Attendance
BUBT
 
Reasoning for Artificial Intelligence Expert
BUBT
 
Auto Room Lighting and Door lock Report
BUBT
 
Auto Room Lighting System
BUBT
 
Doorlock
BUBT
 
Ultra Dense Netwok
BUBT
 
Bangladesh University of Business and Technology
BUBT
 
Art Gallery Management System
BUBT
 
Shop management system
BUBT
 
Ad

Recently uploaded (20)

PPTX
How to Set Maximum Difference Odoo 18 POS
Celine George
 
PDF
ARAL-Orientation_Morning-Session_Day-11.pdf
JoelVilloso1
 
PPTX
CATEGORIES OF NURSING PERSONNEL: HOSPITAL & COLLEGE
PRADEEP ABOTHU
 
PPTX
Stereochemistry-Optical Isomerism in organic compoundsptx
Tarannum Nadaf-Mansuri
 
PDF
The-Ever-Evolving-World-of-Science (1).pdf/7TH CLASS CURIOSITY /1ST CHAPTER/B...
Sandeep Swamy
 
PDF
LAW OF CONTRACT (5 YEAR LLB & UNITARY LLB )- MODULE - 1.& 2 - LEARN THROUGH P...
APARNA T SHAIL KUMAR
 
PPTX
How to Convert an Opportunity into a Quotation in Odoo 18 CRM
Celine George
 
PPTX
How to Handle Salesperson Commision in Odoo 18 Sales
Celine George
 
PPTX
SPINA BIFIDA: NURSING MANAGEMENT .pptx
PRADEEP ABOTHU
 
PPTX
How to Manage Large Scrollbar in Odoo 18 POS
Celine George
 
PDF
Knee Extensor Mechanism Injuries - Orthopedic Radiologic Imaging
Sean M. Fox
 
PPTX
ASRB NET 2023 PREVIOUS YEAR QUESTION PAPER GENETICS AND PLANT BREEDING BY SAT...
Krashi Coaching
 
PDF
community health nursing question paper 2.pdf
Prince kumar
 
PPTX
2025 Winter SWAYAM NPTEL & A Student.pptx
Utsav Yagnik
 
PDF
Dimensions of Societal Planning in Commonism
StefanMz
 
PDF
Chapter-V-DED-Entrepreneurship: Institutions Facilitating Entrepreneurship
Dayanand Huded
 
PPTX
PATIENT ASSIGNMENTS AND NURSING CARE RESPONSIBILITIES.pptx
PRADEEP ABOTHU
 
PDF
Reconstruct, Restore, Reimagine: New Perspectives on Stoke Newington’s Histor...
History of Stoke Newington
 
PDF
The History of Phone Numbers in Stoke Newington by Billy Thomas
History of Stoke Newington
 
PPTX
A PPT on Alfred Lord Tennyson's Ulysses.
Beena E S
 
How to Set Maximum Difference Odoo 18 POS
Celine George
 
ARAL-Orientation_Morning-Session_Day-11.pdf
JoelVilloso1
 
CATEGORIES OF NURSING PERSONNEL: HOSPITAL & COLLEGE
PRADEEP ABOTHU
 
Stereochemistry-Optical Isomerism in organic compoundsptx
Tarannum Nadaf-Mansuri
 
The-Ever-Evolving-World-of-Science (1).pdf/7TH CLASS CURIOSITY /1ST CHAPTER/B...
Sandeep Swamy
 
LAW OF CONTRACT (5 YEAR LLB & UNITARY LLB )- MODULE - 1.& 2 - LEARN THROUGH P...
APARNA T SHAIL KUMAR
 
How to Convert an Opportunity into a Quotation in Odoo 18 CRM
Celine George
 
How to Handle Salesperson Commision in Odoo 18 Sales
Celine George
 
SPINA BIFIDA: NURSING MANAGEMENT .pptx
PRADEEP ABOTHU
 
How to Manage Large Scrollbar in Odoo 18 POS
Celine George
 
Knee Extensor Mechanism Injuries - Orthopedic Radiologic Imaging
Sean M. Fox
 
ASRB NET 2023 PREVIOUS YEAR QUESTION PAPER GENETICS AND PLANT BREEDING BY SAT...
Krashi Coaching
 
community health nursing question paper 2.pdf
Prince kumar
 
2025 Winter SWAYAM NPTEL & A Student.pptx
Utsav Yagnik
 
Dimensions of Societal Planning in Commonism
StefanMz
 
Chapter-V-DED-Entrepreneurship: Institutions Facilitating Entrepreneurship
Dayanand Huded
 
PATIENT ASSIGNMENTS AND NURSING CARE RESPONSIBILITIES.pptx
PRADEEP ABOTHU
 
Reconstruct, Restore, Reimagine: New Perspectives on Stoke Newington’s Histor...
History of Stoke Newington
 
The History of Phone Numbers in Stoke Newington by Billy Thomas
History of Stoke Newington
 
A PPT on Alfred Lord Tennyson's Ulysses.
Beena E S
 

Chapter 2 : Balagurusamy_ Programming ANsI in C

  • 1. CHAPTER 2: Constants, Variables, and Data Types REVIEW QUESTIONS STATE WHETHER THE FOLLOWING STATEMENTS ARE TRUE OR FALSE: (a) Any valid printable ANSII character can be used in an identifier. ( False ) (b) All variables must be given a type when they are declared. ( True ) (c) Declarations can appear anywhere in a program. ( False ) (d) ANSI C treats the variable name and Name to be same. ( False ) (e) The underscore can be used anywhere in an identifier. ( True ) (f) The keyword void is a data type in C. ( True ) (g) Floating point data constants, by default, denote float type values. ( False ) (h) Like variables, constants have a type. ( True ) (i) Character constants are coded using double quotes. (False ) (j) Initialization is the process of assigning a value to a variable at the time of declaration. ( true ) (k) All static variables are automatically initialized to zero. ( True ) (l) The scanf function can be used to read only one value at a time. ( False ) Fill in the blanks with appropriate words: (a)The keyword ……………..can be used to create a data type identifier. Answer: int (b) …………… is the largest value that an unsigned short int type variable can store. Answer: 255 (c) A global variable is also known as …………….variable. Answer: external
  • 2. (d) A variable can be made constant by declaring it with the qualifier ……………. At the time of initialization. Answer: constant Question: What are trigraph characters? How are they useful? Answer: Trigraph characters is one kinds of character which consists of three characters ( Two question marks and followed by another ). Some keyboard does not support some characters. But we can use them by trigraph characters. If a keyboard does not support square brackets, we can still use them in a program using the trigraph ??( and ??) . Question: Describe the four basic data types. How could we extend the range of values they represent? Answer: The basic four data types are: (1) Char (2) Int (3) Float (4) Void We cannot extend the range of character. We could extend the range of integer by using long before integer. We can extend the range of float by using double. To extend the precision further we may use long double. Question: What is an unsigned integer constant? What is the significant of declaring a constant unsigned? Answer: The integer constant which does not take any + or – sign before it is called an unsigned integer constant.
  • 3. We can take the value double using an unsigned integer constant. For example, a signed integer constant have a value between -32768 to +32767, but an unsigned integer constant takes the value between 0 to 65535. Question: Describe the characteristics and purpose of escape sequence characters. Answer: C supports some special back slash character constants, that are used in output function. This characters are known as escape sequence characters. For example, the symbol “n” stands for new line character. Characteristics : (1) They acts as a single character. (2) Each escape sequence character consists of two characters. (3) The first character must be a back slash . Purpose: (1) In a program we used it for new line. (2)In a program we used it for horizontal tab. Question: What is a variable and what is meant by “value” of a variable? Answer: A variable is a data name that may used to store a data value. Like constants that remains unchanged during the execution a program. The meant of value it is a variable name and it can take any value like character, int, float and double. Question: How do variables and symbolic names differ? Answer: A variable may be used to store data value. A variable may take different values at different times during execution of a program. Variables has need to declare at the beginning of the body but after the main.
  • 4. Symbolic names is a unique constants. This constants may appear in a number of place in the program. Symbolic names has need to define at the beginning of a program. Question: State the difference between the declaration of a variable and the definition of a symbolic name? Answer: Variables has need to declare at the beginning of the body but after the main. The syntax for declaring a variable is as follow: Data-type v1,v2,……..vn; v1, v2,……..vn are the names of variables. For example, valid declarations are int count; int number,total; float ratio; Symbolic names has need to define at the beginning of a program. A symbolic name constants is defined as follows: #define symbolic-name value of constant Valid example of constant definations are: #define STRENGTH 100 #define PASS MARK 5 Question: What is initialization? Why it is important? Answer: The process of giving initial values to variables is called initialization. Some examples are int final_value =100;
  • 5. char yes =’x’; double balance =75.84; C permits the initialization of more then one variable using multiple assignment operators.For example the statements p=q=s=0; x=y=z=MAX; are valid. Question: What are the qualifiers that an int can have at a time? Answer: A signed int can take a value between -32768 to 32767 and an unsigned int can take a value 0 to 65535. Question: Describe the purpose of the qualifiers constant and volatile. Answer: We may like the value of certain variables to remain constant during the excution of a program. We can achieve this by declaring the variable with the qualifier constant at the time of initialization. Example: const int class_size=40; ANSI standard defines another qualifier volatile that could be used to tell explicitly the complier that a variables value may be changed at any time by some external sources ( from outside the program). For example: volatile int date; Question: When dealing with very small or very large numbers, what steps would you like you take to improve the accurancy of the calculation? Answer:
  • 6. When we are dealing with a very short number we can improve the accurancy of calculation by using a keyword short before the keyword. Example short int. When we are dealing with a very large number we can improve the accurancy of calculation by using a keyword long before the keyword. Example long int. Question: Which of the following are invalid constants and why? 0.0001 Answer: (valid) 5x1.5 Answer: (Invalid) Reason: Exponent must be an integer. 99999 Answer: Valid Reason: Long integer. +100 Answer: ( valid) 75.45E-2 Answer: ( Valid ) -45.6 Answer: ( Valid ) “15.75” Answer: ( Invalid ) Reason: “” sign is not permitted. -1.79e+4 Answer: (valid)
  • 7. 0.00001234 Answer: ( Valid ) Question: Which of the following are invalid variable and why? Minimum Answer: ( valid ) First.name Answer: ( Invalid ) Reason:. Sign is not permitted. N1+n2 Answer: ( Invalid ) Reason: + sign is not permitted. &name Answer: ( Invalid ) Reason: & is not permitted. Doubles Answer: ( Valid ) Reason: Keyword may be a part of variable name. 3rd_row Answer: ( Invalid ) Reason: First character must be a letter or underscore. n$ Answer: ( Invalid ) Reason: Dollar sign is not permitted. Row1 ( Valid ) Float
  • 8. Answer: ( Invalid ) Reason: float is a keyword. Sum Total Answer: ( Invalid ) Reason: White space is not permitted. Row Total Answer: ( Invalid ) Reason: White space is not permitted. Column total Answer: ( Invalid ) Reason: White space is not permitted. Question: Find errors, if any, in the following declaration statements. { Int x; float letter,DIGIT; double=p,q; exponent alpha,beta; m,n.z:INTEGER short char c; long int m;count; long float temp; getch(); } Error1: intx should have a type. Error2: Line number 6, expression syntax.
  • 9. Error3: Line number 7, Declaration should be properly. Error4:Line number 9, Unreachable code. Problem no 2.1: Write a program to determine and print the sum of the following harmonic series for a given value of n: 1+1/2+1/3+………………+1/n Solve: #include<stdio.h> #include<conio.h> Void main() { int n; float I, sum, t; clrscr(); printf(“1+1/2+1/3+……………+1/nn”); printf(“Enter the value of nn”); scanf(“%d”,&n); sum=0; for(i=1;i<=n;i++) { t=1/i; sum=sum+t; } printf(“%f”,sum); getch(); }
  • 10. Output: 1+1/2+1/3+………….+1/n Enter the value of n 4 2.083333 The value of n should be given interactively through the terminal. Problem no 2.2: Write a program to read the price of an item in decimal form ( like 15.95 ) and print the output in paisa ( like 1595 paisa) . Solve: #include<stdio.h> #include<conio.h> void main() { int b; float a; a=15.95; clrscr(); b=100*a; printf("%d",b); getch(); } Output: 1595 Problem no 2.3: Write a program that’s prints the even numbers from 1 to 100.
  • 11. #include<stdio.h> #include<conio.h> void main() { int i; for(i=1;i<=100;i++) { if(i%2==0) printf(" %d",i); } getch(); } Output 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96 98 100 Problem no 2.4: Write a program that request two float type numbers from the users and then divides the first number by the second and display the result along with the numbers. Solve: #include<stdio.h> #include<conio.h> void main() { float number1, number2, number3; clrscr(); printf("Enter the value of number1 and number2n");
  • 12. scanf("%f %f",&number1,&number2); number3=number1/number2; printf("%f/%f=%f",number1,number2,number3); getch(); Output: Enter the value of number1 and number2 15.5 6.6 15.5/6,6=2.348484 Problem no 2.5: The price of one kg of rice is Rs. 16.75 and one kg of sugar is Rs. 15. Write a program to get these values from the user and display the prices as follows: ***LIST OF ITEMS*** Item Price Rice Rs 16.75 Sugar Rs 15.00 Solve: #include<stdio.h> #include<conio.h> void main () { float Rice,Sugar; Rice=16.75; Sugar=15.00; clrscr(); printf("***LIST OF ITEMS***n");
  • 13. printf("Item tPricen"); printf("RicetRs%.2fn",Rice); printf("SugartRs%.2fn",Sugar); getch(); } Output: ***LIST OF ITEMS*** Item Price Rice Rs16.75 Question: Identify syntax errors in the following program. After correcting, what output would you expect when you execute it. #include<stdio.h> #include<conio.h> #define PI 3.14159 void main() { int R,C; float perimeter; float area; C=PI; R=5; perimeter=2.0*C*R; Area = C*R*R; printf("%f", "%d",&perimeter,&area) } Errors:
  • 14. Cpp 10: Undefined symbol Area. Cpp 12:statement missing,in function{} Cpp12: compound statement missing. Solve: #include<stdio.h> #include<conio.h> #define PI 3.14159 void main() { int R,C; float perimeter,Area; C=PI; R=5; perimeter=2.0*C*R; Area = C*R*R; printf("%f %f",perimeter,Area); getch(); } Reference: http://hstuadmission.blogspot.com/2010/12/solution-programming-in-ansi-c- chapter.html