SlideShare une entreprise Scribd logo
1  sur  2
Solve using matlab codes
Problem 4: (15 points) A simple guessing game. Assume that you have a secret number between
0 and 1000. Write a simple program to allow the user to rind this number by consecutive
guesses. Each time the user enters a guessed number, the program should display if the secret
number is smaller or larger than the guessed number. The program should stop when the number
that the user has entered is equal to the secret number. Also, at the end of the program if the
number of total guesses is less than 10. the program should display: Awesome! You guessed the
secret number with fewer than 10 attempts.
Solution
a=randi(1000);
flag=0;
itr=1;
while flag ==0
b=input('please guess the number ');
if b==a && itr<=10
fprintf(' awesome!!! you guessed in less than 10 attempts ');
flag=1;
else
if b==a && itr>10
fprintf(' congrats!!! you guessed correctly ');
flag=1;
else if b>a
fprintf(' wrong guess. please try again. your guess is greater than the secret number  ');
else
fprintf(' wrong guess. please try again. your guess is lesser than the secret number  ');
end
end
end
itr=itr+1;
end
Solve using matlab codes Problem 4- (15 points) A simple guessing game.docx

Contenu connexe

Plus de mmary455

signment-takeCovalent Activity-doPlocator-assignment take&takeAssignme.docx
signment-takeCovalent Activity-doPlocator-assignment take&takeAssignme.docxsignment-takeCovalent Activity-doPlocator-assignment take&takeAssignme.docx
signment-takeCovalent Activity-doPlocator-assignment take&takeAssignme.docxmmary455
 
Simple interest is the interest cost for one or more periods when the.docx
Simple interest is the interest cost for one or more periods when the.docxSimple interest is the interest cost for one or more periods when the.docx
Simple interest is the interest cost for one or more periods when the.docxmmary455
 
show work 10- Divide 1436 by 203- The answer expressed to the correct.docx
show work 10- Divide 1436 by 203- The answer expressed to the correct.docxshow work 10- Divide 1436 by 203- The answer expressed to the correct.docx
show work 10- Divide 1436 by 203- The answer expressed to the correct.docxmmary455
 
Show the effect of dollar appeciation and depreciation with the yen on.docx
Show the effect of dollar appeciation and depreciation with the yen on.docxShow the effect of dollar appeciation and depreciation with the yen on.docx
Show the effect of dollar appeciation and depreciation with the yen on.docxmmary455
 
Solubility products Ks(Fe(OH)2) - 4-9 x 10 ^ -17 Ks(Fe(OH)3) - 2-8 x 1.docx
Solubility products Ks(Fe(OH)2) - 4-9 x 10 ^ -17 Ks(Fe(OH)3) - 2-8 x 1.docxSolubility products Ks(Fe(OH)2) - 4-9 x 10 ^ -17 Ks(Fe(OH)3) - 2-8 x 1.docx
Solubility products Ks(Fe(OH)2) - 4-9 x 10 ^ -17 Ks(Fe(OH)3) - 2-8 x 1.docxmmary455
 
Sodium fluoride is added to many municipal water supplies to reduce to.docx
Sodium fluoride is added to many municipal water supplies to reduce to.docxSodium fluoride is added to many municipal water supplies to reduce to.docx
Sodium fluoride is added to many municipal water supplies to reduce to.docxmmary455
 
Societal Dimension of IPESolutionInternational political economy was t.docx
Societal Dimension of IPESolutionInternational political economy was t.docxSocietal Dimension of IPESolutionInternational political economy was t.docx
Societal Dimension of IPESolutionInternational political economy was t.docxmmary455
 
Soil & GW Remediation (Civil and Environmental Engineering) SolutionQn.docx
Soil & GW Remediation (Civil and Environmental Engineering) SolutionQn.docxSoil & GW Remediation (Civil and Environmental Engineering) SolutionQn.docx
Soil & GW Remediation (Civil and Environmental Engineering) SolutionQn.docxmmary455
 
Show that the worst-case time complexity for Binary Search is given by.docx
Show that the worst-case time complexity for Binary Search is given by.docxShow that the worst-case time complexity for Binary Search is given by.docx
Show that the worst-case time complexity for Binary Search is given by.docxmmary455
 
Since Linux is an international operating system you can configure it.docx
Since Linux is an international operating system you can configure it.docxSince Linux is an international operating system you can configure it.docx
Since Linux is an international operating system you can configure it.docxmmary455
 
Sinking fund bands- Require the issuer to set aside assets in order r.docx
Sinking fund bands-  Require the issuer to set aside assets in order r.docxSinking fund bands-  Require the issuer to set aside assets in order r.docx
Sinking fund bands- Require the issuer to set aside assets in order r.docxmmary455
 
Simplify-Write answers in the form of a+bi where a and b are real numb.docx
Simplify-Write answers in the form of a+bi where a and b are real numb.docxSimplify-Write answers in the form of a+bi where a and b are real numb.docx
Simplify-Write answers in the form of a+bi where a and b are real numb.docxmmary455
 
Simplify- 1 + 3 x+4 1 + 9 x-2 Solutio.docx
Simplify-    1 +      3    x+4         1 +      9    x-2       Solutio.docxSimplify-    1 +      3    x+4         1 +      9    x-2       Solutio.docx
Simplify- 1 + 3 x+4 1 + 9 x-2 Solutio.docxmmary455
 
Case- The Long- Loud Silence Background As the director of health info.docx
Case- The Long- Loud Silence Background As the director of health info.docxCase- The Long- Loud Silence Background As the director of health info.docx
Case- The Long- Loud Silence Background As the director of health info.docxmmary455
 
Case 4-3 The Baptist Foundation of Arizona- The Whistleblower Hotline.docx
Case 4-3 The Baptist Foundation of Arizona- The Whistleblower Hotline.docxCase 4-3 The Baptist Foundation of Arizona- The Whistleblower Hotline.docx
Case 4-3 The Baptist Foundation of Arizona- The Whistleblower Hotline.docxmmary455
 
Case 5-1 David L- Miller- Portrait of a White-Collar Criminal There is.docx
Case 5-1 David L- Miller- Portrait of a White-Collar Criminal There is.docxCase 5-1 David L- Miller- Portrait of a White-Collar Criminal There is.docx
Case 5-1 David L- Miller- Portrait of a White-Collar Criminal There is.docxmmary455
 
Carbon steel is an active metal meaning it has low corrosion resistanc.docx
Carbon steel is an active metal meaning it has low corrosion resistanc.docxCarbon steel is an active metal meaning it has low corrosion resistanc.docx
Carbon steel is an active metal meaning it has low corrosion resistanc.docxmmary455
 
Carbon dioxide in the atmosphere traps heat from the sun and makes lif.docx
Carbon dioxide in the atmosphere traps heat from the sun and makes lif.docxCarbon dioxide in the atmosphere traps heat from the sun and makes lif.docx
Carbon dioxide in the atmosphere traps heat from the sun and makes lif.docxmmary455
 
Carnival Corporation has recently placed into service some of the larg.docx
Carnival Corporation has recently placed into service some of the larg.docxCarnival Corporation has recently placed into service some of the larg.docx
Carnival Corporation has recently placed into service some of the larg.docxmmary455
 
Canadian Income Tax Question Tiffany MacGraw- a Canadian citizen- left.docx
Canadian Income Tax Question Tiffany MacGraw- a Canadian citizen- left.docxCanadian Income Tax Question Tiffany MacGraw- a Canadian citizen- left.docx
Canadian Income Tax Question Tiffany MacGraw- a Canadian citizen- left.docxmmary455
 

Plus de mmary455 (20)

signment-takeCovalent Activity-doPlocator-assignment take&takeAssignme.docx
signment-takeCovalent Activity-doPlocator-assignment take&takeAssignme.docxsignment-takeCovalent Activity-doPlocator-assignment take&takeAssignme.docx
signment-takeCovalent Activity-doPlocator-assignment take&takeAssignme.docx
 
Simple interest is the interest cost for one or more periods when the.docx
Simple interest is the interest cost for one or more periods when the.docxSimple interest is the interest cost for one or more periods when the.docx
Simple interest is the interest cost for one or more periods when the.docx
 
show work 10- Divide 1436 by 203- The answer expressed to the correct.docx
show work 10- Divide 1436 by 203- The answer expressed to the correct.docxshow work 10- Divide 1436 by 203- The answer expressed to the correct.docx
show work 10- Divide 1436 by 203- The answer expressed to the correct.docx
 
Show the effect of dollar appeciation and depreciation with the yen on.docx
Show the effect of dollar appeciation and depreciation with the yen on.docxShow the effect of dollar appeciation and depreciation with the yen on.docx
Show the effect of dollar appeciation and depreciation with the yen on.docx
 
Solubility products Ks(Fe(OH)2) - 4-9 x 10 ^ -17 Ks(Fe(OH)3) - 2-8 x 1.docx
Solubility products Ks(Fe(OH)2) - 4-9 x 10 ^ -17 Ks(Fe(OH)3) - 2-8 x 1.docxSolubility products Ks(Fe(OH)2) - 4-9 x 10 ^ -17 Ks(Fe(OH)3) - 2-8 x 1.docx
Solubility products Ks(Fe(OH)2) - 4-9 x 10 ^ -17 Ks(Fe(OH)3) - 2-8 x 1.docx
 
Sodium fluoride is added to many municipal water supplies to reduce to.docx
Sodium fluoride is added to many municipal water supplies to reduce to.docxSodium fluoride is added to many municipal water supplies to reduce to.docx
Sodium fluoride is added to many municipal water supplies to reduce to.docx
 
Societal Dimension of IPESolutionInternational political economy was t.docx
Societal Dimension of IPESolutionInternational political economy was t.docxSocietal Dimension of IPESolutionInternational political economy was t.docx
Societal Dimension of IPESolutionInternational political economy was t.docx
 
Soil & GW Remediation (Civil and Environmental Engineering) SolutionQn.docx
Soil & GW Remediation (Civil and Environmental Engineering) SolutionQn.docxSoil & GW Remediation (Civil and Environmental Engineering) SolutionQn.docx
Soil & GW Remediation (Civil and Environmental Engineering) SolutionQn.docx
 
Show that the worst-case time complexity for Binary Search is given by.docx
Show that the worst-case time complexity for Binary Search is given by.docxShow that the worst-case time complexity for Binary Search is given by.docx
Show that the worst-case time complexity for Binary Search is given by.docx
 
Since Linux is an international operating system you can configure it.docx
Since Linux is an international operating system you can configure it.docxSince Linux is an international operating system you can configure it.docx
Since Linux is an international operating system you can configure it.docx
 
Sinking fund bands- Require the issuer to set aside assets in order r.docx
Sinking fund bands-  Require the issuer to set aside assets in order r.docxSinking fund bands-  Require the issuer to set aside assets in order r.docx
Sinking fund bands- Require the issuer to set aside assets in order r.docx
 
Simplify-Write answers in the form of a+bi where a and b are real numb.docx
Simplify-Write answers in the form of a+bi where a and b are real numb.docxSimplify-Write answers in the form of a+bi where a and b are real numb.docx
Simplify-Write answers in the form of a+bi where a and b are real numb.docx
 
Simplify- 1 + 3 x+4 1 + 9 x-2 Solutio.docx
Simplify-    1 +      3    x+4         1 +      9    x-2       Solutio.docxSimplify-    1 +      3    x+4         1 +      9    x-2       Solutio.docx
Simplify- 1 + 3 x+4 1 + 9 x-2 Solutio.docx
 
Case- The Long- Loud Silence Background As the director of health info.docx
Case- The Long- Loud Silence Background As the director of health info.docxCase- The Long- Loud Silence Background As the director of health info.docx
Case- The Long- Loud Silence Background As the director of health info.docx
 
Case 4-3 The Baptist Foundation of Arizona- The Whistleblower Hotline.docx
Case 4-3 The Baptist Foundation of Arizona- The Whistleblower Hotline.docxCase 4-3 The Baptist Foundation of Arizona- The Whistleblower Hotline.docx
Case 4-3 The Baptist Foundation of Arizona- The Whistleblower Hotline.docx
 
Case 5-1 David L- Miller- Portrait of a White-Collar Criminal There is.docx
Case 5-1 David L- Miller- Portrait of a White-Collar Criminal There is.docxCase 5-1 David L- Miller- Portrait of a White-Collar Criminal There is.docx
Case 5-1 David L- Miller- Portrait of a White-Collar Criminal There is.docx
 
Carbon steel is an active metal meaning it has low corrosion resistanc.docx
Carbon steel is an active metal meaning it has low corrosion resistanc.docxCarbon steel is an active metal meaning it has low corrosion resistanc.docx
Carbon steel is an active metal meaning it has low corrosion resistanc.docx
 
Carbon dioxide in the atmosphere traps heat from the sun and makes lif.docx
Carbon dioxide in the atmosphere traps heat from the sun and makes lif.docxCarbon dioxide in the atmosphere traps heat from the sun and makes lif.docx
Carbon dioxide in the atmosphere traps heat from the sun and makes lif.docx
 
Carnival Corporation has recently placed into service some of the larg.docx
Carnival Corporation has recently placed into service some of the larg.docxCarnival Corporation has recently placed into service some of the larg.docx
Carnival Corporation has recently placed into service some of the larg.docx
 
Canadian Income Tax Question Tiffany MacGraw- a Canadian citizen- left.docx
Canadian Income Tax Question Tiffany MacGraw- a Canadian citizen- left.docxCanadian Income Tax Question Tiffany MacGraw- a Canadian citizen- left.docx
Canadian Income Tax Question Tiffany MacGraw- a Canadian citizen- left.docx
 

Dernier

Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Shubhangi Sonawane
 
Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.MateoGardella
 
Gardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch LetterGardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch LetterMateoGardella
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin ClassesCeline George
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
An Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdfAn Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdfSanaAli374401
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxnegromaestrong
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxVishalSingh1417
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfChris Hunter
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...christianmathematics
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxAreebaZafar22
 

Dernier (20)

Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
 
Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.
 
Gardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch LetterGardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch Letter
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
An Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdfAn Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdf
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdf
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 

Solve using matlab codes Problem 4- (15 points) A simple guessing game.docx

  • 1. Solve using matlab codes Problem 4: (15 points) A simple guessing game. Assume that you have a secret number between 0 and 1000. Write a simple program to allow the user to rind this number by consecutive guesses. Each time the user enters a guessed number, the program should display if the secret number is smaller or larger than the guessed number. The program should stop when the number that the user has entered is equal to the secret number. Also, at the end of the program if the number of total guesses is less than 10. the program should display: Awesome! You guessed the secret number with fewer than 10 attempts. Solution a=randi(1000); flag=0; itr=1; while flag ==0 b=input('please guess the number '); if b==a && itr<=10 fprintf(' awesome!!! you guessed in less than 10 attempts '); flag=1; else if b==a && itr>10 fprintf(' congrats!!! you guessed correctly '); flag=1; else if b>a fprintf(' wrong guess. please try again. your guess is greater than the secret number '); else fprintf(' wrong guess. please try again. your guess is lesser than the secret number '); end end end itr=itr+1; end