Some Practice Problems for the C++ Exam and Solutions for the Problems


a.  The output will be  "less than 10".  b



Download 194,42 Kb.
Pdf ko'rish
bet3/4
Sana30.12.2021
Hajmi194,42 Kb.
#192878
1   2   3   4
Bog'liq
C101-PracticeProblems

14 a.  The output will be  "less than 10". 

b.  The output will be  "greater than 15". 

c.  The output will be  "less than 10". 

d.  There is no value for  n  that will cause the output to be  "not interesting".  That part of the 

code can never be executed! 

 

 

15.  Using  do...while... in this situation makes the code a little simpler. 



 

   int n; 

 

   do 


   { 

      cout << "Enter a non-negative integer: "; 

      cin  >> n; 

 

      if (n < 0) 



         cout << "The integer you entered is negative." << endl; 

   } 


   while (n < 0); 

  

 



16 a.  The output of the code fragment as it is written will be 

 

n is not zero. 



The square of n is 0. 

 

 



The  reason  for  this  is  that  the  "if"  part  assigns  the  value    0    to    n  ,  and  the  value  returned  by  that 

assignment  statement  is    0  ,  so  this  is  treated  as  "false",  which  causes  the  alternative  statement  to  be 

executed.  But even though the program prints  "n is not zero.", in fact,  n  does have the value 

zero after the conditional statement is finished. 

 


Download 194,42 Kb.

Do'stlaringiz bilan baham:
1   2   3   4




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish