SlideShare a Scribd company logo
left0UNIVERSITI TUN HUSSEIN ONN MALAYSIA<br />FACULTY OF MECHANICAL AND MANUFACTURING ENGINEERING <br />BTI 1022: COMPUTER PROGRAMMING<br />LAB EXERCISE 7 LOOP, GOTO and FUNCTION intro<br />Exercise 1:<br />,[object Object],int main()<br />{<br />    double price1, price2 ,price3,price4, price5, price6, price7, totalprice=0;<br />    printf(quot;
Program to calculate the average and total price of the 7 itemsquot;
);<br />    printf(quot;
 Enter price of item: RMquot;
);<br />    scanf(quot;
%lfquot;
, &price1);<br />    totalprice +=price1;<br />    printf(quot;
 Enter price of item: RMquot;
);<br />    scanf(quot;
%lfquot;
, &price2);<br />    totalprice +=price2;<br />     printf(quot;
 Enter price of item: RMquot;
);<br />    scanf(quot;
%lfquot;
, &price3);<br />    totalprice +=price3;<br />     printf(quot;
 Enter price of item : RMquot;
);<br />    scanf(quot;
%lfquot;
, &price4);<br />    totalprice +=price4;<br />     printf(quot;
 Enter price of item : RMquot;
);<br />    scanf(quot;
%lfquot;
, &price5);<br />    totalprice +=price5;<br />     printf(quot;
 Enter price of item : RMquot;
);<br />    scanf(quot;
%lfquot;
, &price6);<br />    totalprice +=price6;<br />     printf(quot;
 Enter price of item : RMquot;
);<br />    scanf(quot;
%lfquot;
, &price7);<br />    totalprice +=price7;<br />    printf(quot;
 The total price of the item is: RM%0.2lf quot;
, totalprice);<br />    printf(quot;
 The average price of the item is: RM%0.2lf quot;
, totalprice/7);<br />    printf(quot;
End of programquot;
);<br />    getch();<br />    return 0;<br />}<br />,[object Object]
What does the program do?
Why do you need 7 variables to hold the prices of the items?
Why is the variable totalprice initialized to 0?
Identify the set of statements that are repeated many times in the program

More Related Content

What's hot

C programming
C programmingC programming
C program to check leap year
C program to check leap year C program to check leap year
C program to check leap year
mohdshanu
 
Bti1022 lab sheet 3
Bti1022 lab sheet 3Bti1022 lab sheet 3
Bti1022 lab sheet 3
alish sha
 
Lab 1
Lab 1Lab 1
C Programming Language Part 7
C Programming Language Part 7C Programming Language Part 7
C Programming Language Part 7
Rumman Ansari
 
Practical write a c program to reverse a given number
Practical write a c program to reverse a given numberPractical write a c program to reverse a given number
Practical write a c program to reverse a given number
Mainak Sasmal
 
Plsql programs
Plsql programsPlsql programs
Loop control structure
Loop control structureLoop control structure
Loop control structure
Karan Pandey
 
Cinfo
CinfoCinfo
Cinfo
teach4uin
 
C Programming Language Part 6
C Programming Language Part 6C Programming Language Part 6
C Programming Language Part 6
Rumman Ansari
 
C Language Programs
C Language Programs C Language Programs
C Language Programs
Mansi Tyagi
 
Python as a calculator
Python as a calculatorPython as a calculator
Python as a calculator
HemantChaurasia8
 
Few Operator used in c++
Few Operator used in c++Few Operator used in c++
Few Operator used in c++
sunny khan
 
Lab4 (pfl) 20_mdele136(ausaf)
Lab4 (pfl) 20_mdele136(ausaf)Lab4 (pfl) 20_mdele136(ausaf)
Lab4 (pfl) 20_mdele136(ausaf)
Ausaf Ahmad
 
Muzzammilrashid
MuzzammilrashidMuzzammilrashid
Muzzammilrashid
muzzammilrashid
 
Cs291 assignment solution
Cs291 assignment solutionCs291 assignment solution
Cs291 assignment solution
Kuntal Bhowmick
 
C pointers
C pointersC pointers
CSIS 138 JavaScript Class3
CSIS 138 JavaScript Class3CSIS 138 JavaScript Class3
CSIS 138 JavaScript Class3
Teresa Pelkie
 
Qprgs
QprgsQprgs
Lab5 (pfl) 20_mdele136(ausaf)
Lab5 (pfl) 20_mdele136(ausaf)Lab5 (pfl) 20_mdele136(ausaf)
Lab5 (pfl) 20_mdele136(ausaf)
Ausaf Ahmad
 

What's hot (20)

C programming
C programmingC programming
C programming
 
C program to check leap year
C program to check leap year C program to check leap year
C program to check leap year
 
Bti1022 lab sheet 3
Bti1022 lab sheet 3Bti1022 lab sheet 3
Bti1022 lab sheet 3
 
Lab 1
Lab 1Lab 1
Lab 1
 
C Programming Language Part 7
C Programming Language Part 7C Programming Language Part 7
C Programming Language Part 7
 
Practical write a c program to reverse a given number
Practical write a c program to reverse a given numberPractical write a c program to reverse a given number
Practical write a c program to reverse a given number
 
Plsql programs
Plsql programsPlsql programs
Plsql programs
 
Loop control structure
Loop control structureLoop control structure
Loop control structure
 
Cinfo
CinfoCinfo
Cinfo
 
C Programming Language Part 6
C Programming Language Part 6C Programming Language Part 6
C Programming Language Part 6
 
C Language Programs
C Language Programs C Language Programs
C Language Programs
 
Python as a calculator
Python as a calculatorPython as a calculator
Python as a calculator
 
Few Operator used in c++
Few Operator used in c++Few Operator used in c++
Few Operator used in c++
 
Lab4 (pfl) 20_mdele136(ausaf)
Lab4 (pfl) 20_mdele136(ausaf)Lab4 (pfl) 20_mdele136(ausaf)
Lab4 (pfl) 20_mdele136(ausaf)
 
Muzzammilrashid
MuzzammilrashidMuzzammilrashid
Muzzammilrashid
 
Cs291 assignment solution
Cs291 assignment solutionCs291 assignment solution
Cs291 assignment solution
 
C pointers
C pointersC pointers
C pointers
 
CSIS 138 JavaScript Class3
CSIS 138 JavaScript Class3CSIS 138 JavaScript Class3
CSIS 138 JavaScript Class3
 
Qprgs
QprgsQprgs
Qprgs
 
Lab5 (pfl) 20_mdele136(ausaf)
Lab5 (pfl) 20_mdele136(ausaf)Lab5 (pfl) 20_mdele136(ausaf)
Lab5 (pfl) 20_mdele136(ausaf)
 

Viewers also liked

Sustainable Reading - Concept Workshop
Sustainable Reading - Concept WorkshopSustainable Reading - Concept Workshop
Sustainable Reading - Concept Workshop
storyofxu
 
Situación actual de las relaciones entre docentes y estudiantes.
Situación actual de las relaciones entre docentes y estudiantes.Situación actual de las relaciones entre docentes y estudiantes.
Situación actual de las relaciones entre docentes y estudiantes.
Leonardo Eras
 
It activity 6.3 catapults
It activity 6.3 catapultsIt activity 6.3 catapults
It activity 6.3 catapultslibbyheli
 
Henry's open mind
Henry's open mindHenry's open mind
Henry's open mind
nplisko
 
Brochure talleres Lizandra Barbuto y Jhon Croft - Quito Ecuador Abril de 2016
Brochure talleres Lizandra Barbuto y Jhon Croft - Quito Ecuador Abril de 2016Brochure talleres Lizandra Barbuto y Jhon Croft - Quito Ecuador Abril de 2016
Brochure talleres Lizandra Barbuto y Jhon Croft - Quito Ecuador Abril de 2016
Corporación Dijoma
 
Ud 0 final juani
Ud 0 final juaniUd 0 final juani
Ud 0 final juanijuanapardo
 
Tech4101 1
Tech4101 1Tech4101 1
Puc IU
Puc IUPuc IU
Puc IU
Linh Vo
 
Procrastinate Now, why put it off!
Procrastinate Now, why put it off!Procrastinate Now, why put it off!
Procrastinate Now, why put it off!
Brad Hyde
 
Shrinkage Estimation of Linear Panel Data Models Under Nearly Singular Design
Shrinkage Estimation of Linear Panel Data Models Under Nearly Singular DesignShrinkage Estimation of Linear Panel Data Models Under Nearly Singular Design
Shrinkage Estimation of Linear Panel Data Models Under Nearly Singular Design
raffaelesaggio
 
หมั่นโถวเสริมโปรตีนจากใบมะรุม
หมั่นโถวเสริมโปรตีนจากใบมะรุมหมั่นโถวเสริมโปรตีนจากใบมะรุม
หมั่นโถวเสริมโปรตีนจากใบมะรุมNattAA
 
Vasilisa_Zulfikarova_cmf2013
Vasilisa_Zulfikarova_cmf2013Vasilisa_Zulfikarova_cmf2013
Vasilisa_Zulfikarova_cmf2013Evgeny Vasyuk
 
Get your city ready for #GivingTuesday 2014 - lessons from Baltimore
Get your city ready for #GivingTuesday 2014 - lessons from BaltimoreGet your city ready for #GivingTuesday 2014 - lessons from Baltimore
Get your city ready for #GivingTuesday 2014 - lessons from Baltimore
Heather Fields
 
Awsをつかってみた
AwsをつかってみたAwsをつかってみた
Awsをつかってみた
Tomoyuki Tochihira
 
Have a blessed 2011 ahead
Have a blessed  2011 aheadHave a blessed  2011 ahead
Have a blessed 2011 ahead
hosiosky
 
Recruitment services for it services
Recruitment services for it servicesRecruitment services for it services
Recruitment services for it services
crescitasolutions
 
Lil riding hood safe path
Lil riding hood safe pathLil riding hood safe path
Lil riding hood safe path
Yuval Esroni
 
Teaching Unity at Mind Candy
Teaching Unity at Mind CandyTeaching Unity at Mind Candy
Teaching Unity at Mind Candy
Mark Baker
 

Viewers also liked (20)

Sustainable Reading - Concept Workshop
Sustainable Reading - Concept WorkshopSustainable Reading - Concept Workshop
Sustainable Reading - Concept Workshop
 
Situación actual de las relaciones entre docentes y estudiantes.
Situación actual de las relaciones entre docentes y estudiantes.Situación actual de las relaciones entre docentes y estudiantes.
Situación actual de las relaciones entre docentes y estudiantes.
 
It activity 6.3 catapults
It activity 6.3 catapultsIt activity 6.3 catapults
It activity 6.3 catapults
 
الرسم المظوري
الرسم المظوريالرسم المظوري
الرسم المظوري
 
الأسبوع التاسع
الأسبوع التاسعالأسبوع التاسع
الأسبوع التاسع
 
Henry's open mind
Henry's open mindHenry's open mind
Henry's open mind
 
Brochure talleres Lizandra Barbuto y Jhon Croft - Quito Ecuador Abril de 2016
Brochure talleres Lizandra Barbuto y Jhon Croft - Quito Ecuador Abril de 2016Brochure talleres Lizandra Barbuto y Jhon Croft - Quito Ecuador Abril de 2016
Brochure talleres Lizandra Barbuto y Jhon Croft - Quito Ecuador Abril de 2016
 
Ud 0 final juani
Ud 0 final juaniUd 0 final juani
Ud 0 final juani
 
Tech4101 1
Tech4101 1Tech4101 1
Tech4101 1
 
Puc IU
Puc IUPuc IU
Puc IU
 
Procrastinate Now, why put it off!
Procrastinate Now, why put it off!Procrastinate Now, why put it off!
Procrastinate Now, why put it off!
 
Shrinkage Estimation of Linear Panel Data Models Under Nearly Singular Design
Shrinkage Estimation of Linear Panel Data Models Under Nearly Singular DesignShrinkage Estimation of Linear Panel Data Models Under Nearly Singular Design
Shrinkage Estimation of Linear Panel Data Models Under Nearly Singular Design
 
หมั่นโถวเสริมโปรตีนจากใบมะรุม
หมั่นโถวเสริมโปรตีนจากใบมะรุมหมั่นโถวเสริมโปรตีนจากใบมะรุม
หมั่นโถวเสริมโปรตีนจากใบมะรุม
 
Vasilisa_Zulfikarova_cmf2013
Vasilisa_Zulfikarova_cmf2013Vasilisa_Zulfikarova_cmf2013
Vasilisa_Zulfikarova_cmf2013
 
Get your city ready for #GivingTuesday 2014 - lessons from Baltimore
Get your city ready for #GivingTuesday 2014 - lessons from BaltimoreGet your city ready for #GivingTuesday 2014 - lessons from Baltimore
Get your city ready for #GivingTuesday 2014 - lessons from Baltimore
 
Awsをつかってみた
AwsをつかってみたAwsをつかってみた
Awsをつかってみた
 
Have a blessed 2011 ahead
Have a blessed  2011 aheadHave a blessed  2011 ahead
Have a blessed 2011 ahead
 
Recruitment services for it services
Recruitment services for it servicesRecruitment services for it services
Recruitment services for it services
 
Lil riding hood safe path
Lil riding hood safe pathLil riding hood safe path
Lil riding hood safe path
 
Teaching Unity at Mind Candy
Teaching Unity at Mind CandyTeaching Unity at Mind Candy
Teaching Unity at Mind Candy
 

Similar to Bti1022 lab sheet 7

Dti2143 lab sheet 8
Dti2143 lab sheet 8Dti2143 lab sheet 8
Dti2143 lab sheet 8
alish sha
 
Dti2143 lab sheet 7
Dti2143 lab sheet 7Dti2143 lab sheet 7
Dti2143 lab sheet 7
alish sha
 
Dti2143 dam31303 lab sheet 8
Dti2143 dam31303 lab sheet 8Dti2143 dam31303 lab sheet 8
Dti2143 dam31303 lab sheet 8
alish sha
 
Bti1022 lab sheet 8
Bti1022 lab sheet 8Bti1022 lab sheet 8
Bti1022 lab sheet 8
alish sha
 
Bti1022 lab sheet 8
Bti1022 lab sheet 8Bti1022 lab sheet 8
Bti1022 lab sheet 8
alish sha
 
Dti2143 lab sheet 9
Dti2143 lab sheet 9Dti2143 lab sheet 9
Dti2143 lab sheet 9
alish sha
 
E1 – FundamentalsPlease refer to announcements for details about.docx
E1 – FundamentalsPlease refer to announcements for details about.docxE1 – FundamentalsPlease refer to announcements for details about.docx
E1 – FundamentalsPlease refer to announcements for details about.docx
jacksnathalie
 
C Programming Lab.pdf
C Programming Lab.pdfC Programming Lab.pdf
C Programming Lab.pdf
MOJO89
 
C important questions
C important questionsC important questions
C important questions
JYOTI RANJAN PAL
 
Ch5(loops)
Ch5(loops)Ch5(loops)
Ch5(loops)
Uğurcan Uzer
 
Core programming in c
Core programming in cCore programming in c
Core programming in c
Rahul Pandit
 
Here is the grading matrix where the TA will leave feedback. If you .docx
Here is the grading matrix where the TA will leave feedback. If you .docxHere is the grading matrix where the TA will leave feedback. If you .docx
Here is the grading matrix where the TA will leave feedback. If you .docx
trappiteboni
 
Bti1022 lab sheet 9 10
Bti1022 lab sheet 9 10Bti1022 lab sheet 9 10
Bti1022 lab sheet 9 10
alish sha
 
C file
C fileC file
C code examples
C code examplesC code examples
Programming fundamental 02
Programming fundamental 02Programming fundamental 02
Programming fundamental 02
Suhail Akraam
 
Write a program to check a given number is prime or not
Write a program to check a given number is prime or notWrite a program to check a given number is prime or not
Write a program to check a given number is prime or not
aluavi
 
Presentation1
Presentation1Presentation1
Presentation1
daisy_arcangel
 
Lab 2
Lab 2Lab 2
Simple Java Programs
Simple Java ProgramsSimple Java Programs
Simple Java Programs
AravindSankaran
 

Similar to Bti1022 lab sheet 7 (20)

Dti2143 lab sheet 8
Dti2143 lab sheet 8Dti2143 lab sheet 8
Dti2143 lab sheet 8
 
Dti2143 lab sheet 7
Dti2143 lab sheet 7Dti2143 lab sheet 7
Dti2143 lab sheet 7
 
Dti2143 dam31303 lab sheet 8
Dti2143 dam31303 lab sheet 8Dti2143 dam31303 lab sheet 8
Dti2143 dam31303 lab sheet 8
 
Bti1022 lab sheet 8
Bti1022 lab sheet 8Bti1022 lab sheet 8
Bti1022 lab sheet 8
 
Bti1022 lab sheet 8
Bti1022 lab sheet 8Bti1022 lab sheet 8
Bti1022 lab sheet 8
 
Dti2143 lab sheet 9
Dti2143 lab sheet 9Dti2143 lab sheet 9
Dti2143 lab sheet 9
 
E1 – FundamentalsPlease refer to announcements for details about.docx
E1 – FundamentalsPlease refer to announcements for details about.docxE1 – FundamentalsPlease refer to announcements for details about.docx
E1 – FundamentalsPlease refer to announcements for details about.docx
 
C Programming Lab.pdf
C Programming Lab.pdfC Programming Lab.pdf
C Programming Lab.pdf
 
C important questions
C important questionsC important questions
C important questions
 
Ch5(loops)
Ch5(loops)Ch5(loops)
Ch5(loops)
 
Core programming in c
Core programming in cCore programming in c
Core programming in c
 
Here is the grading matrix where the TA will leave feedback. If you .docx
Here is the grading matrix where the TA will leave feedback. If you .docxHere is the grading matrix where the TA will leave feedback. If you .docx
Here is the grading matrix where the TA will leave feedback. If you .docx
 
Bti1022 lab sheet 9 10
Bti1022 lab sheet 9 10Bti1022 lab sheet 9 10
Bti1022 lab sheet 9 10
 
C file
C fileC file
C file
 
C code examples
C code examplesC code examples
C code examples
 
Programming fundamental 02
Programming fundamental 02Programming fundamental 02
Programming fundamental 02
 
Write a program to check a given number is prime or not
Write a program to check a given number is prime or notWrite a program to check a given number is prime or not
Write a program to check a given number is prime or not
 
Presentation1
Presentation1Presentation1
Presentation1
 
Lab 2
Lab 2Lab 2
Lab 2
 
Simple Java Programs
Simple Java ProgramsSimple Java Programs
Simple Java Programs
 

More from alish sha

T22016 – how to answer with ubs 9
T22016 – how to answer with ubs 9T22016 – how to answer with ubs 9
T22016 – how to answer with ubs 9
alish sha
 
July 2014 theory exam (theory)
July 2014 theory exam (theory)July 2014 theory exam (theory)
July 2014 theory exam (theory)
alish sha
 
Accounting basic equation
Accounting basic equation Accounting basic equation
Accounting basic equation
alish sha
 
It 302 computerized accounting (week 2) - sharifah
It 302   computerized accounting (week 2) - sharifahIt 302   computerized accounting (week 2) - sharifah
It 302 computerized accounting (week 2) - sharifah
alish sha
 
It 302 computerized accounting (week 1) - sharifah
It 302   computerized accounting (week 1) - sharifahIt 302   computerized accounting (week 1) - sharifah
It 302 computerized accounting (week 1) - sharifah
alish sha
 
What are the causes of conflicts (Bahasa Malaysia)
What are the causes of conflicts (Bahasa Malaysia)What are the causes of conflicts (Bahasa Malaysia)
What are the causes of conflicts (Bahasa Malaysia)
alish sha
 
Lab 9 sem ii_12_13
Lab 9 sem ii_12_13Lab 9 sem ii_12_13
Lab 9 sem ii_12_13
alish sha
 
Lab 10 sem ii_12_13
Lab 10 sem ii_12_13Lab 10 sem ii_12_13
Lab 10 sem ii_12_13
alish sha
 
Lab 6
Lab 6Lab 6
Lab 6
alish sha
 
Lab 5 2012/2012
Lab 5 2012/2012Lab 5 2012/2012
Lab 5 2012/2012
alish sha
 
Purpose elaborate
Purpose elaboratePurpose elaborate
Purpose elaborate
alish sha
 
Lab sheet 1
Lab sheet 1Lab sheet 1
Lab sheet 1
alish sha
 
Test 1 alish schema 1
Test 1 alish schema 1Test 1 alish schema 1
Test 1 alish schema 1
alish sha
 
Lab 6 sem ii_11_12
Lab 6 sem ii_11_12Lab 6 sem ii_11_12
Lab 6 sem ii_11_12
alish sha
 
Test 1 skema q&a
Test 1 skema q&aTest 1 skema q&a
Test 1 skema q&a
alish sha
 
Test 1 skema q&a
Test 1 skema q&aTest 1 skema q&a
Test 1 skema q&a
alish sha
 
Final project
Final projectFinal project
Final projectalish sha
 
Final project
Final projectFinal project
Final project
alish sha
 
Attn list test
Attn list testAttn list test
Attn list testalish sha
 
Carry markdam31303
Carry markdam31303Carry markdam31303
Carry markdam31303
alish sha
 

More from alish sha (20)

T22016 – how to answer with ubs 9
T22016 – how to answer with ubs 9T22016 – how to answer with ubs 9
T22016 – how to answer with ubs 9
 
July 2014 theory exam (theory)
July 2014 theory exam (theory)July 2014 theory exam (theory)
July 2014 theory exam (theory)
 
Accounting basic equation
Accounting basic equation Accounting basic equation
Accounting basic equation
 
It 302 computerized accounting (week 2) - sharifah
It 302   computerized accounting (week 2) - sharifahIt 302   computerized accounting (week 2) - sharifah
It 302 computerized accounting (week 2) - sharifah
 
It 302 computerized accounting (week 1) - sharifah
It 302   computerized accounting (week 1) - sharifahIt 302   computerized accounting (week 1) - sharifah
It 302 computerized accounting (week 1) - sharifah
 
What are the causes of conflicts (Bahasa Malaysia)
What are the causes of conflicts (Bahasa Malaysia)What are the causes of conflicts (Bahasa Malaysia)
What are the causes of conflicts (Bahasa Malaysia)
 
Lab 9 sem ii_12_13
Lab 9 sem ii_12_13Lab 9 sem ii_12_13
Lab 9 sem ii_12_13
 
Lab 10 sem ii_12_13
Lab 10 sem ii_12_13Lab 10 sem ii_12_13
Lab 10 sem ii_12_13
 
Lab 6
Lab 6Lab 6
Lab 6
 
Lab 5 2012/2012
Lab 5 2012/2012Lab 5 2012/2012
Lab 5 2012/2012
 
Purpose elaborate
Purpose elaboratePurpose elaborate
Purpose elaborate
 
Lab sheet 1
Lab sheet 1Lab sheet 1
Lab sheet 1
 
Test 1 alish schema 1
Test 1 alish schema 1Test 1 alish schema 1
Test 1 alish schema 1
 
Lab 6 sem ii_11_12
Lab 6 sem ii_11_12Lab 6 sem ii_11_12
Lab 6 sem ii_11_12
 
Test 1 skema q&a
Test 1 skema q&aTest 1 skema q&a
Test 1 skema q&a
 
Test 1 skema q&a
Test 1 skema q&aTest 1 skema q&a
Test 1 skema q&a
 
Final project
Final projectFinal project
Final project
 
Final project
Final projectFinal project
Final project
 
Attn list test
Attn list testAttn list test
Attn list test
 
Carry markdam31303
Carry markdam31303Carry markdam31303
Carry markdam31303
 

Bti1022 lab sheet 7