Chapter 3 : Balagurusamy Programming ANSI in C

BUBT
BUBTStudent

Chapter 3 : Balagurusamy Programming ANSI in C Review question solution pdf

CHAPTER-3
Operators & Expressions
Review Questions:
3.1: True or False.
(a) All arithmetic operators have the same level of precedence. Ans. False
(b) The modulus operators can be used only with integers. Ans. True
(c) The operators <=, >= and != all enjoy the same level of priority. Ans. False
(d) During modulo division, the sign of the result is positive, if both the operands
are
of the same sign. Ans. True
(e) In C , if the data item is zero , it is considered false. Ans. True
(f) The expression!(x<=y) is same as the expression x>y. Ans. True
(g) A unary expression consists of only one operand with no operators. Ans.
False
(h) Associativity is used to decide which of several different expression is
evaluated first. Ans. False
(i) An expression statement is terminated with a period. Ans. False
(j) During the evaluation of mixed expressions, an implicit cast is generated
automatically. Ans. True
(k) An explicit cast can be used to change the expression. Ans. True
(l) Parentheses can be used to change the order of evaluation expressions. Ans.
True
3.2: Fill in the blank.
(a) The expression containing all the integer operands is called (arithmetic)
expression.
(b) The operator (%) cannot be used with the real operands.
(c) C supports as many as (6) relational operators.
(d) An expression that combines two or more relational expressions is termed as
(logical) expressions.
(e) The (sizeof ) operator returns the number of bytes the operand occupied.
(f) The order of evaluation can be used changed by using (parentheses) in an
expression.
(g) The use of (implicit type) on a variable can change its types in the memory.
(h) (Precedence) is used to determine the order in which different operators in an
expressions are evaluated.
3.3: Given the statement
Int a=10,b=20,c;
Determine true or false.
(a)The statement a=+10, is valid. Ans. True
(b) The expression a + 4/6 * 6/2 evaluates to 11. Ans. False
(c) The expression b + 3/2 * 2/3 evaluates to20. Ans. True
(d) The statement a+=b gives the values 30 to a and 20 to b. Ans. True
(e) The statement ++a++; gives the value 12 to a. Ans. False
(f)The statement a=1/b; assigns the value 0.5 to a. Ans. False
3.4:Declared a as int and b as float , state whether the following statement are true
or false.
(a)The statement a=1/3+1/3+1/3;assigns the value 1 to a. Ans .False
(b)The statement b=1.0/3.0+1.0/3.0+1.0/3.0;assgns a value 1.0 to b. Ans. True
(c)The statement b=1.0/3.0*3.0; gives a value 1.0 to b.Ans. True
(d)The statement b=1.0/3.0+2.0/3.0;assigns a value 1.0 to b.Ans. True
(e) The statement a=15/10.0+3/2; assigns a value 3 to a. Ans. False
3.5 Which of the following expression are true?
(a) !(5+5)>=10)Ans. False
(b) 5+5==10||1+3==5 Ans. True
(c) 5>10||10<20&&3<5 Ans. True
(d) 10!=15&&!(10<20)||15>30 Ans. False
3.6 Which of the following arithmetic expression is valid? If valid, give the value
of the expression; otherwise give reason.
(a) 25/3%2 Ans. Invalid
(b) +9/4+5 Ans. Valid
(c) 7.5%3 Ans. Invalid
(d) 14%3+7%2 Ans. Valid
(e)-14%3 Ans. Valid
(f) 15.25+-5.0 Ans. Valid
(g) (5/3)*3+5%3 Ans. Valid
(h) 21%(int)4.5 Ans. Valid
3.7:Write C assignment statement to evaluate the following equation:
(a)
Solution:
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int r,h;
float area;
clrscr();
printf("Enter the value of r,hn");
scanf(“%d %d",&r,&h);
area=(3.1416*r*r+2*3.1416*r*h);
printf("%f",area);
getch();
}
(d)
Solution:
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int m,h,v;
float Energy;
clrscr();
acceleration=9.8;
printf("Enter the value of m,h,vn");
scanf("%d%d%d",&m,&h,&v);
x=(9.8*h);
y=(v*v)/2;
Energy=m*(x+y);
printf("%f",Energy);
getch();}
(b)
Solution:
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int m1,m2,x,y;
float T;
clrscr();
printf("Enter the value of m1,m2n");
scanf("%f %f",&m1,&m2);
x=(2*m1*m2*9.8);
y=(m1+m2);
T=x/y;
printf("%f",T);
getch();
}
(c)
Solution:
#include<stdio.h>
#include<conio.h>
#include<math.h>
#define cosx
void main()
{
int a,b,p,q,r,n,x;
float side;
clrscr();
printf("Enter the value of a,b,xn");
scanf("%d%d%d",&a,&b,&x);
p=(a*a+b*b);
r=(2*a*b);
n=cos(x);
side=sqrt(p-r*n);
printf("%f",side);
getch();
}
3.8:Indentyfy unnecessary parantheses in the following artimatic expression.
(a)(x-(y/5)+z)%8+25
(b)(x-y)*p+q
(c)(m*n)+(-x/y)
(d)x/3*y
3.9: Find the errors, if any, in the following assignment statement and rectify them.
(a)x=y=z=0.5,2.0, -5.75;
(b)m=++a*5;
(c)y=sqrt(100);
(d)p*=x/y;
(e)s/=5;
(f)a=b++-c*2;
3.10: Determine the value of each of the following logical expressions if a=5,b=10
and c=-6.
(a) a>b && a<c Value:0
(b) a<b && a>c Value:1
(c) a==c || b>a Value:1
(d) b>15 && c<0 || a>o Value:1
3.11:What is the out put of the following program?
Solution:
#include<stdio.h>
#include<conio.h>
void main();
{
/*...characters......*/
char x;
int y;
x=100;
y=125;
printf("%cn",x);
printf("%cn",y);
printf("%dn",x);
getch();
}
Output: 100
3.12:Find the output of the following program?
Solution:
#include<stdio.h>
#include<conio.h>
void main()
{
/*....increment......*/
int x=100;
clrscr();
printf("%dn",10+x++);
printf("%dn",10+ ++x);
getch();}
Output:
110
112
3.13:What is printed by the following program?
Solution:
#include<stdio.h>
#include<conio.h>
void main()
{
int x=5,y=10,z=10;
clrscr();
x=y==z;
printf("%d",x);
getch();
}
Output: 1
314:What is the output of the following program ?
Solution:
#include<stdio.h>
#include<conio.h>
void main()
{
int x=100,y=200;
clrscr();
printf("%d",(x>y)?x:y);
}
Output: 200
3.15:What is the output of the following program?
Solution:
#include<stdio.h>
#include<conio.h>
void main()
{
unsigned x=1;
signed char y=-1;
clrscr();
if(x>y)
printf("x>y");
else
printf("x<=y");
getch();
}
Output:
No
3.16:What is the output of the following program? Explain the output.
Solution:
#include<stdio.h>
#include<conio.h>
void main()
{
int x=10;
clrscr();
if(x=20)
printf("TRUE");
else
printf("FALSE");
getch();
}
Output: TRUE
3.17: What is the error in each of the following statement?
(a) if(m==1 & n!=0)
printf("OK");
Output:
Error: Correct 'and' sign is '&&'
(b) if(x=<5)
printf("Jump");
Output:
Error: =<
Correct: <=
3.18:What is the error, if any ,in the following segment?
int x=10;
float y=4.25;
x= y%x;
Error: Illegal use of floating point.
3.19:What is printed when the following is execute?
Solution:
#include<stdio.h>
#include<conio.h>
void main()
{
int m;
clrscr();
for(m=0;m<3;++m)
printf("%dn",(m%2)?m:m+2);
getch();
}
Output:
2
1
4
3.20:What is the output of the following statement?
Solution:
#include<stdio.h>
#include<conio.h>
void main()
{
int m=-14,n=3;
clrscr();
printf("%dn",m/n*10);
n=-n;
printf("%d",m/n*10);
getch();
}
Output:
-40
40
Reference:
http://hstuadmission.blogspot.com/2010/12/solution-programming-in-ansi-c-
chapter.html

Recomendados

Chapter 4 : Balagurusamy Programming ANSI in C por
Chapter 4 : Balagurusamy Programming ANSI in CChapter 4 : Balagurusamy Programming ANSI in C
Chapter 4 : Balagurusamy Programming ANSI in CBUBT
7.4K vistas20 diapositivas
Chapter 2 : Balagurusamy_ Programming ANsI in C por
Chapter 2 :  Balagurusamy_ Programming ANsI in CChapter 2 :  Balagurusamy_ Programming ANsI in C
Chapter 2 : Balagurusamy_ Programming ANsI in CBUBT
5.5K vistas14 diapositivas
Chapter 5 Balagurusamy Programming ANSI in c por
Chapter 5 Balagurusamy Programming ANSI  in cChapter 5 Balagurusamy Programming ANSI  in c
Chapter 5 Balagurusamy Programming ANSI in cBUBT
10.8K vistas36 diapositivas
Chapter 6 Balagurusamy Programming ANSI in c por
Chapter 6  Balagurusamy Programming ANSI  in cChapter 6  Balagurusamy Programming ANSI  in c
Chapter 6 Balagurusamy Programming ANSI in cBUBT
8.5K vistas43 diapositivas
Let us c chapter 4 solution por
Let us c chapter 4 solutionLet us c chapter 4 solution
Let us c chapter 4 solutionrohit kumar
14.4K vistas4 diapositivas
Chapter 5 exercises Balagurusamy Programming ANSI in c por
Chapter 5 exercises Balagurusamy Programming ANSI  in cChapter 5 exercises Balagurusamy Programming ANSI  in c
Chapter 5 exercises Balagurusamy Programming ANSI in cBUBT
2.3K vistas41 diapositivas

Más contenido relacionado

La actualidad más candente

Chapter 8 c solution por
Chapter 8 c solutionChapter 8 c solution
Chapter 8 c solutionAzhar Javed
9.1K vistas87 diapositivas
Let us C (by yashvant Kanetkar) chapter 3 Solution por
Let us C   (by yashvant Kanetkar) chapter 3 SolutionLet us C   (by yashvant Kanetkar) chapter 3 Solution
Let us C (by yashvant Kanetkar) chapter 3 SolutionHazrat Bilal
28.3K vistas14 diapositivas
Ansi c por
Ansi cAnsi c
Ansi cdayaramjatt001
5.1K vistas33 diapositivas
Let us c(by yashwant kanetkar) chapter 2 solution por
Let us c(by yashwant kanetkar) chapter 2 solutionLet us c(by yashwant kanetkar) chapter 2 solution
Let us c(by yashwant kanetkar) chapter 2 solutionrohit kumar
43K vistas27 diapositivas
Data Input and Output por
Data Input and OutputData Input and Output
Data Input and OutputSabik T S
1.7K vistas14 diapositivas
Let us c (5th and 12th edition by YASHVANT KANETKAR) chapter 2 solution por
Let us c (5th and 12th edition by YASHVANT KANETKAR) chapter 2 solutionLet us c (5th and 12th edition by YASHVANT KANETKAR) chapter 2 solution
Let us c (5th and 12th edition by YASHVANT KANETKAR) chapter 2 solutionHazrat Bilal
4.4K vistas27 diapositivas

La actualidad más candente(20)

Chapter 8 c solution por Azhar Javed
Chapter 8 c solutionChapter 8 c solution
Chapter 8 c solution
Azhar Javed9.1K vistas
Let us C (by yashvant Kanetkar) chapter 3 Solution por Hazrat Bilal
Let us C   (by yashvant Kanetkar) chapter 3 SolutionLet us C   (by yashvant Kanetkar) chapter 3 Solution
Let us C (by yashvant Kanetkar) chapter 3 Solution
Hazrat Bilal28.3K vistas
Let us c(by yashwant kanetkar) chapter 2 solution por rohit kumar
Let us c(by yashwant kanetkar) chapter 2 solutionLet us c(by yashwant kanetkar) chapter 2 solution
Let us c(by yashwant kanetkar) chapter 2 solution
rohit kumar43K vistas
Data Input and Output por Sabik T S
Data Input and OutputData Input and Output
Data Input and Output
Sabik T S1.7K vistas
Let us c (5th and 12th edition by YASHVANT KANETKAR) chapter 2 solution por Hazrat Bilal
Let us c (5th and 12th edition by YASHVANT KANETKAR) chapter 2 solutionLet us c (5th and 12th edition by YASHVANT KANETKAR) chapter 2 solution
Let us c (5th and 12th edition by YASHVANT KANETKAR) chapter 2 solution
Hazrat Bilal4.4K vistas
Let us c(by Yashwant Kanetkar) 5th edition solution chapter 1 por rohit kumar
Let us c(by Yashwant Kanetkar) 5th edition solution chapter 1Let us c(by Yashwant Kanetkar) 5th edition solution chapter 1
Let us c(by Yashwant Kanetkar) 5th edition solution chapter 1
rohit kumar50.8K vistas
LET US C (5th EDITION) CHAPTER 2 ANSWERS por KavyaSharma65
LET US C (5th EDITION) CHAPTER 2 ANSWERSLET US C (5th EDITION) CHAPTER 2 ANSWERS
LET US C (5th EDITION) CHAPTER 2 ANSWERS
KavyaSharma65574 vistas
C if else por Ritwik Das
C if elseC if else
C if else
Ritwik Das13.8K vistas
Solid C++ by Example por Olve Maudal
Solid C++ by ExampleSolid C++ by Example
Solid C++ by Example
Olve Maudal20.4K vistas
Object Oriented Programming Using C++ Practical File por Harjinder Singh
Object Oriented Programming Using C++ Practical FileObject Oriented Programming Using C++ Practical File
Object Oriented Programming Using C++ Practical File
Harjinder Singh14.9K vistas
C Programming Storage classes, Recursion por Sreedhar Chowdam
C Programming Storage classes, RecursionC Programming Storage classes, Recursion
C Programming Storage classes, Recursion
Sreedhar Chowdam379 vistas
Call by value por Dharani G
Call by valueCall by value
Call by value
Dharani G8.7K vistas
C programming Lab 1 por Zaibi Gondal
C programming Lab 1C programming Lab 1
C programming Lab 1
Zaibi Gondal4.2K vistas

Similar a Chapter 3 : Balagurusamy Programming ANSI in C

Revision1 C programming por
Revision1 C programmingRevision1 C programming
Revision1 C programmingKho コー。イエー。イエン
2.4K vistas12 diapositivas
Revision1schema C programming por
Revision1schema C programmingRevision1schema C programming
Revision1schema C programmingKho コー。イエー。イエン
7K vistas15 diapositivas
C Programming Interview Questions por
C Programming Interview QuestionsC Programming Interview Questions
C Programming Interview QuestionsGradeup
1.3K vistas21 diapositivas
VTU PCD Model Question Paper - Programming in C por
VTU PCD Model Question Paper - Programming in CVTU PCD Model Question Paper - Programming in C
VTU PCD Model Question Paper - Programming in CSyed Mustafa
20K vistas34 diapositivas
answer-model-qp-15-pcd13pcd por
answer-model-qp-15-pcd13pcdanswer-model-qp-15-pcd13pcd
answer-model-qp-15-pcd13pcdSyed Mustafa
2.3K vistas34 diapositivas
C interview question answer 2 por
C interview question answer 2C interview question answer 2
C interview question answer 2Amit Kapoor
22.4K vistas70 diapositivas

Similar a Chapter 3 : Balagurusamy Programming ANSI in C (20)

C Programming Interview Questions por Gradeup
C Programming Interview QuestionsC Programming Interview Questions
C Programming Interview Questions
Gradeup1.3K vistas
VTU PCD Model Question Paper - Programming in C por Syed Mustafa
VTU PCD Model Question Paper - Programming in CVTU PCD Model Question Paper - Programming in C
VTU PCD Model Question Paper - Programming in C
Syed Mustafa20K vistas
answer-model-qp-15-pcd13pcd por Syed Mustafa
answer-model-qp-15-pcd13pcdanswer-model-qp-15-pcd13pcd
answer-model-qp-15-pcd13pcd
Syed Mustafa2.3K vistas
C interview question answer 2 por Amit Kapoor
C interview question answer 2C interview question answer 2
C interview question answer 2
Amit Kapoor22.4K vistas
Java căn bản - Chapter3 por Vince Vo
Java căn bản - Chapter3Java căn bản - Chapter3
Java căn bản - Chapter3
Vince Vo549 vistas
(Www.entrance exam.net)-tcs placement sample paper 2 por Pamidimukkala Sivani
(Www.entrance exam.net)-tcs placement sample paper 2(Www.entrance exam.net)-tcs placement sample paper 2
(Www.entrance exam.net)-tcs placement sample paper 2
Pamidimukkala Sivani1.8K vistas
C Operators and Control Structures.pptx por ramanathan2006
C Operators and Control Structures.pptxC Operators and Control Structures.pptx
C Operators and Control Structures.pptx
ramanathan20062 vistas
C aptitude.2doc por Srikanth
C aptitude.2docC aptitude.2doc
C aptitude.2doc
Srikanth3.6K vistas
Operators inc c language por Tanmay Modi
Operators inc c languageOperators inc c language
Operators inc c language
Tanmay Modi275 vistas
Operators and expressions in c language por tanmaymodi4
Operators and expressions in c languageOperators and expressions in c language
Operators and expressions in c language
tanmaymodi42.3K vistas
Questions 1 – 5 are TrueFalse. Mark A for True and B for False..docx por catheryncouper
Questions 1 – 5 are TrueFalse. Mark A for True and B for False..docxQuestions 1 – 5 are TrueFalse. Mark A for True and B for False..docx
Questions 1 – 5 are TrueFalse. Mark A for True and B for False..docx
catheryncouper6 vistas
MATLAB Questions and Answers.pdf por ahmed8651
MATLAB Questions and Answers.pdfMATLAB Questions and Answers.pdf
MATLAB Questions and Answers.pdf
ahmed8651172 vistas

Más de BUBT

Lab report cover page por
Lab report cover page Lab report cover page
Lab report cover page BUBT
2K vistas1 diapositiva
Project report title cover page por
Project report title cover pageProject report title cover page
Project report title cover pageBUBT
171 vistas1 diapositiva
Implementation Of GSM Based Fire Alarm and Protection System por
Implementation Of GSM Based Fire Alarm and Protection SystemImplementation Of GSM Based Fire Alarm and Protection System
Implementation Of GSM Based Fire Alarm and Protection SystemBUBT
1.5K vistas26 diapositivas
Student Attendance por
Student AttendanceStudent Attendance
Student AttendanceBUBT
468 vistas22 diapositivas
Reasoning for Artificial Intelligence Expert por
Reasoning for Artificial Intelligence ExpertReasoning for Artificial Intelligence Expert
Reasoning for Artificial Intelligence ExpertBUBT
44 vistas6 diapositivas
Auto Room Lighting and Door lock Report por
Auto Room Lighting and Door lock ReportAuto Room Lighting and Door lock Report
Auto Room Lighting and Door lock ReportBUBT
151 vistas13 diapositivas

Más de BUBT(12)

Lab report cover page por BUBT
Lab report cover page Lab report cover page
Lab report cover page
BUBT2K vistas
Project report title cover page por BUBT
Project report title cover pageProject report title cover page
Project report title cover page
BUBT171 vistas
Implementation Of GSM Based Fire Alarm and Protection System por BUBT
Implementation Of GSM Based Fire Alarm and Protection SystemImplementation Of GSM Based Fire Alarm and Protection System
Implementation Of GSM Based Fire Alarm and Protection System
BUBT1.5K vistas
Student Attendance por BUBT
Student AttendanceStudent Attendance
Student Attendance
BUBT468 vistas
Reasoning for Artificial Intelligence Expert por BUBT
Reasoning for Artificial Intelligence ExpertReasoning for Artificial Intelligence Expert
Reasoning for Artificial Intelligence Expert
BUBT44 vistas
Auto Room Lighting and Door lock Report por BUBT
Auto Room Lighting and Door lock ReportAuto Room Lighting and Door lock Report
Auto Room Lighting and Door lock Report
BUBT151 vistas
Auto Room Lighting System por BUBT
Auto Room Lighting SystemAuto Room Lighting System
Auto Room Lighting System
BUBT3K vistas
Doorlock por BUBT
DoorlockDoorlock
Doorlock
BUBT162 vistas
Ultra Dense Netwok por BUBT
Ultra Dense NetwokUltra Dense Netwok
Ultra Dense Netwok
BUBT2.4K vistas
Bangladesh University of Business and Technology por BUBT
Bangladesh University of Business and Technology Bangladesh University of Business and Technology
Bangladesh University of Business and Technology
BUBT46 vistas
Art Gallery Management System por BUBT
Art Gallery Management SystemArt Gallery Management System
Art Gallery Management System
BUBT11.4K vistas
Shop management system por BUBT
Shop management systemShop management system
Shop management system
BUBT1.1K vistas

Último

11.28.23 Social Capital and Social Exclusion.pptx por
11.28.23 Social Capital and Social Exclusion.pptx11.28.23 Social Capital and Social Exclusion.pptx
11.28.23 Social Capital and Social Exclusion.pptxmary850239
304 vistas25 diapositivas
Psychology KS5 por
Psychology KS5Psychology KS5
Psychology KS5WestHatch
103 vistas5 diapositivas
unidad 3.pdf por
unidad 3.pdfunidad 3.pdf
unidad 3.pdfMarcosRodriguezUcedo
106 vistas38 diapositivas
MercerJesse2.1Doc.pdf por
MercerJesse2.1Doc.pdfMercerJesse2.1Doc.pdf
MercerJesse2.1Doc.pdfjessemercerail
237 vistas5 diapositivas
When Sex Gets Complicated: Porn, Affairs, & Cybersex por
When Sex Gets Complicated: Porn, Affairs, & CybersexWhen Sex Gets Complicated: Porn, Affairs, & Cybersex
When Sex Gets Complicated: Porn, Affairs, & CybersexMarlene Maheu
73 vistas73 diapositivas
Ch. 7 Political Participation and Elections.pptx por
Ch. 7 Political Participation and Elections.pptxCh. 7 Political Participation and Elections.pptx
Ch. 7 Political Participation and Elections.pptxRommel Regala
105 vistas11 diapositivas

Último(20)

11.28.23 Social Capital and Social Exclusion.pptx por mary850239
11.28.23 Social Capital and Social Exclusion.pptx11.28.23 Social Capital and Social Exclusion.pptx
11.28.23 Social Capital and Social Exclusion.pptx
mary850239304 vistas
Psychology KS5 por WestHatch
Psychology KS5Psychology KS5
Psychology KS5
WestHatch103 vistas
When Sex Gets Complicated: Porn, Affairs, & Cybersex por Marlene Maheu
When Sex Gets Complicated: Porn, Affairs, & CybersexWhen Sex Gets Complicated: Porn, Affairs, & Cybersex
When Sex Gets Complicated: Porn, Affairs, & Cybersex
Marlene Maheu73 vistas
Ch. 7 Political Participation and Elections.pptx por Rommel Regala
Ch. 7 Political Participation and Elections.pptxCh. 7 Political Participation and Elections.pptx
Ch. 7 Political Participation and Elections.pptx
Rommel Regala105 vistas
Monthly Information Session for MV Asterix (November) por Esquimalt MFRC
Monthly Information Session for MV Asterix (November)Monthly Information Session for MV Asterix (November)
Monthly Information Session for MV Asterix (November)
Esquimalt MFRC58 vistas
AUDIENCE - BANDURA.pptx por iammrhaywood
AUDIENCE - BANDURA.pptxAUDIENCE - BANDURA.pptx
AUDIENCE - BANDURA.pptx
iammrhaywood89 vistas
Relationship of psychology with other subjects. por palswagata2003
Relationship of psychology with other subjects.Relationship of psychology with other subjects.
Relationship of psychology with other subjects.
palswagata200348 vistas
Psychology KS4 por WestHatch
Psychology KS4Psychology KS4
Psychology KS4
WestHatch90 vistas
BÀI TẬP BỔ TRỢ TIẾNG ANH 11 THEO ĐƠN VỊ BÀI HỌC - CẢ NĂM - CÓ FILE NGHE (GLOB... por Nguyen Thanh Tu Collection
BÀI TẬP BỔ TRỢ TIẾNG ANH 11 THEO ĐƠN VỊ BÀI HỌC - CẢ NĂM - CÓ FILE NGHE (GLOB...BÀI TẬP BỔ TRỢ TIẾNG ANH 11 THEO ĐƠN VỊ BÀI HỌC - CẢ NĂM - CÓ FILE NGHE (GLOB...
BÀI TẬP BỔ TRỢ TIẾNG ANH 11 THEO ĐƠN VỊ BÀI HỌC - CẢ NĂM - CÓ FILE NGHE (GLOB...
Solar System and Galaxies.pptx por DrHafizKosar
Solar System and Galaxies.pptxSolar System and Galaxies.pptx
Solar System and Galaxies.pptx
DrHafizKosar94 vistas
Dance KS5 Breakdown por WestHatch
Dance KS5 BreakdownDance KS5 Breakdown
Dance KS5 Breakdown
WestHatch86 vistas
S1_SD_Resources Walkthrough.pptx por LAZAROAREVALO1
S1_SD_Resources Walkthrough.pptxS1_SD_Resources Walkthrough.pptx
S1_SD_Resources Walkthrough.pptx
LAZAROAREVALO153 vistas
Narration lesson plan por TARIQ KHAN
Narration lesson planNarration lesson plan
Narration lesson plan
TARIQ KHAN59 vistas

Chapter 3 : Balagurusamy Programming ANSI in C

  • 1. CHAPTER-3 Operators & Expressions Review Questions: 3.1: True or False. (a) All arithmetic operators have the same level of precedence. Ans. False (b) The modulus operators can be used only with integers. Ans. True (c) The operators <=, >= and != all enjoy the same level of priority. Ans. False (d) During modulo division, the sign of the result is positive, if both the operands are of the same sign. Ans. True (e) In C , if the data item is zero , it is considered false. Ans. True (f) The expression!(x<=y) is same as the expression x>y. Ans. True (g) A unary expression consists of only one operand with no operators. Ans. False (h) Associativity is used to decide which of several different expression is evaluated first. Ans. False (i) An expression statement is terminated with a period. Ans. False
  • 2. (j) During the evaluation of mixed expressions, an implicit cast is generated automatically. Ans. True (k) An explicit cast can be used to change the expression. Ans. True (l) Parentheses can be used to change the order of evaluation expressions. Ans. True 3.2: Fill in the blank. (a) The expression containing all the integer operands is called (arithmetic) expression. (b) The operator (%) cannot be used with the real operands. (c) C supports as many as (6) relational operators. (d) An expression that combines two or more relational expressions is termed as (logical) expressions. (e) The (sizeof ) operator returns the number of bytes the operand occupied. (f) The order of evaluation can be used changed by using (parentheses) in an expression. (g) The use of (implicit type) on a variable can change its types in the memory. (h) (Precedence) is used to determine the order in which different operators in an expressions are evaluated. 3.3: Given the statement Int a=10,b=20,c; Determine true or false. (a)The statement a=+10, is valid. Ans. True (b) The expression a + 4/6 * 6/2 evaluates to 11. Ans. False (c) The expression b + 3/2 * 2/3 evaluates to20. Ans. True (d) The statement a+=b gives the values 30 to a and 20 to b. Ans. True
  • 3. (e) The statement ++a++; gives the value 12 to a. Ans. False (f)The statement a=1/b; assigns the value 0.5 to a. Ans. False 3.4:Declared a as int and b as float , state whether the following statement are true or false. (a)The statement a=1/3+1/3+1/3;assigns the value 1 to a. Ans .False (b)The statement b=1.0/3.0+1.0/3.0+1.0/3.0;assgns a value 1.0 to b. Ans. True (c)The statement b=1.0/3.0*3.0; gives a value 1.0 to b.Ans. True (d)The statement b=1.0/3.0+2.0/3.0;assigns a value 1.0 to b.Ans. True (e) The statement a=15/10.0+3/2; assigns a value 3 to a. Ans. False 3.5 Which of the following expression are true? (a) !(5+5)>=10)Ans. False (b) 5+5==10||1+3==5 Ans. True (c) 5>10||10<20&&3<5 Ans. True (d) 10!=15&&!(10<20)||15>30 Ans. False 3.6 Which of the following arithmetic expression is valid? If valid, give the value of the expression; otherwise give reason. (a) 25/3%2 Ans. Invalid (b) +9/4+5 Ans. Valid (c) 7.5%3 Ans. Invalid (d) 14%3+7%2 Ans. Valid (e)-14%3 Ans. Valid (f) 15.25+-5.0 Ans. Valid (g) (5/3)*3+5%3 Ans. Valid
  • 4. (h) 21%(int)4.5 Ans. Valid 3.7:Write C assignment statement to evaluate the following equation: (a) Solution: #include<stdio.h> #include<conio.h> #include<math.h> void main() { int r,h; float area; clrscr(); printf("Enter the value of r,hn"); scanf(“%d %d",&r,&h); area=(3.1416*r*r+2*3.1416*r*h); printf("%f",area); getch(); } (d) Solution: #include<stdio.h> #include<conio.h> #include<math.h> void main()
  • 5. { int m,h,v; float Energy; clrscr(); acceleration=9.8; printf("Enter the value of m,h,vn"); scanf("%d%d%d",&m,&h,&v); x=(9.8*h); y=(v*v)/2; Energy=m*(x+y); printf("%f",Energy); getch();} (b) Solution: #include<stdio.h> #include<conio.h> #include<math.h> void main() { int m1,m2,x,y; float T; clrscr(); printf("Enter the value of m1,m2n");
  • 6. scanf("%f %f",&m1,&m2); x=(2*m1*m2*9.8); y=(m1+m2); T=x/y; printf("%f",T); getch(); } (c) Solution: #include<stdio.h> #include<conio.h> #include<math.h> #define cosx void main() { int a,b,p,q,r,n,x; float side; clrscr(); printf("Enter the value of a,b,xn"); scanf("%d%d%d",&a,&b,&x); p=(a*a+b*b); r=(2*a*b); n=cos(x); side=sqrt(p-r*n); printf("%f",side);
  • 7. getch(); } 3.8:Indentyfy unnecessary parantheses in the following artimatic expression. (a)(x-(y/5)+z)%8+25 (b)(x-y)*p+q (c)(m*n)+(-x/y) (d)x/3*y 3.9: Find the errors, if any, in the following assignment statement and rectify them. (a)x=y=z=0.5,2.0, -5.75; (b)m=++a*5; (c)y=sqrt(100); (d)p*=x/y; (e)s/=5; (f)a=b++-c*2; 3.10: Determine the value of each of the following logical expressions if a=5,b=10 and c=-6. (a) a>b && a<c Value:0 (b) a<b && a>c Value:1 (c) a==c || b>a Value:1 (d) b>15 && c<0 || a>o Value:1 3.11:What is the out put of the following program? Solution: #include<stdio.h> #include<conio.h>
  • 8. void main(); { /*...characters......*/ char x; int y; x=100; y=125; printf("%cn",x); printf("%cn",y); printf("%dn",x); getch(); } Output: 100 3.12:Find the output of the following program? Solution: #include<stdio.h> #include<conio.h> void main() { /*....increment......*/ int x=100; clrscr(); printf("%dn",10+x++); printf("%dn",10+ ++x); getch();}
  • 9. Output: 110 112 3.13:What is printed by the following program? Solution: #include<stdio.h> #include<conio.h> void main() { int x=5,y=10,z=10; clrscr(); x=y==z; printf("%d",x); getch(); } Output: 1 314:What is the output of the following program ? Solution: #include<stdio.h> #include<conio.h> void main() { int x=100,y=200; clrscr(); printf("%d",(x>y)?x:y);
  • 10. } Output: 200 3.15:What is the output of the following program? Solution: #include<stdio.h> #include<conio.h> void main() { unsigned x=1; signed char y=-1; clrscr(); if(x>y) printf("x>y"); else printf("x<=y"); getch(); } Output: No 3.16:What is the output of the following program? Explain the output. Solution: #include<stdio.h> #include<conio.h> void main() {
  • 11. int x=10; clrscr(); if(x=20) printf("TRUE"); else printf("FALSE"); getch(); } Output: TRUE 3.17: What is the error in each of the following statement? (a) if(m==1 & n!=0) printf("OK"); Output: Error: Correct 'and' sign is '&&' (b) if(x=<5) printf("Jump"); Output: Error: =< Correct: <= 3.18:What is the error, if any ,in the following segment? int x=10; float y=4.25; x= y%x; Error: Illegal use of floating point.
  • 12. 3.19:What is printed when the following is execute? Solution: #include<stdio.h> #include<conio.h> void main() { int m; clrscr(); for(m=0;m<3;++m) printf("%dn",(m%2)?m:m+2); getch(); } Output: 2 1 4 3.20:What is the output of the following statement? Solution: #include<stdio.h> #include<conio.h> void main() { int m=-14,n=3; clrscr(); printf("%dn",m/n*10);