SlideShare a Scribd company logo
1 of 4
left0UNIVERSITI TUN HUSSEIN ONN MALAYSIA<br />FACULTY OF MECHANICAL AND MANUFACTURING ENGINEERING <br />DTI 2143: COMPUTER PROGRAMMING<br />LAB EXERCISE 6  LOOP AND FUNCTION (INTRO)<br />Exercise 1:<br />,[object Object],#include<stdio.h><br />#include<conio.h><br />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 />    <br />    getch();<br />    return 0;<br />}<br />1.1 Study program 1.0 carefully, then compile and execute it.<br />,[object Object]
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

Call by value
Call by valueCall by value
Call by valueDharani G
 
How c program execute in c program
How c program execute in c program How c program execute in c program
How c program execute in c program Rumman Ansari
 
Increment and Decrement operators in C++
Increment and Decrement operators in C++Increment and Decrement operators in C++
Increment and Decrement operators in C++Neeru Mittal
 
Programming fundamentals
Programming fundamentalsProgramming fundamentals
Programming fundamentalsZaibi Gondal
 
C programming Lab 2
C programming Lab 2C programming Lab 2
C programming Lab 2Zaibi Gondal
 
Write a program that accepts percentage from the user and displays its grade ...
Write a program that accepts percentage from the user and displays its grade ...Write a program that accepts percentage from the user and displays its grade ...
Write a program that accepts percentage from the user and displays its grade ...Farwa Aqeel
 
Factorial Program in C
Factorial Program in CFactorial Program in C
Factorial Program in CHitesh Kumar
 
Template matching
Template matchingTemplate matching
Template matchingHasan Ijaz
 
Basic of c programming www.eakanchha.com
Basic of c programming www.eakanchha.comBasic of c programming www.eakanchha.com
Basic of c programming www.eakanchha.comAkanchha Agrawal
 
Introduction to Computer and Programing - Lecture 04
Introduction to Computer and Programing - Lecture 04Introduction to Computer and Programing - Lecture 04
Introduction to Computer and Programing - Lecture 04hassaanciit
 
Exp 3-2 d422 (1)
Exp 3-2  d422 (1)Exp 3-2  d422 (1)
Exp 3-2 d422 (1)Omkar Rane
 
Lecture 8 increment_and_decrement_operators
Lecture 8 increment_and_decrement_operatorsLecture 8 increment_and_decrement_operators
Lecture 8 increment_and_decrement_operatorseShikshak
 
C Language Programs
C Language Programs C Language Programs
C Language Programs Mansi Tyagi
 
C Programming Language Part 7
C Programming Language Part 7C Programming Language Part 7
C Programming Language Part 7Rumman Ansari
 

What's hot (19)

Call by value
Call by valueCall by value
Call by value
 
How c program execute in c program
How c program execute in c program How c program execute in c program
How c program execute in c program
 
Practical no 6
Practical no 6Practical no 6
Practical no 6
 
Increment and Decrement operators in C++
Increment and Decrement operators in C++Increment and Decrement operators in C++
Increment and Decrement operators in C++
 
Programming fundamentals
Programming fundamentalsProgramming fundamentals
Programming fundamentals
 
Activities on Operands
Activities on OperandsActivities on Operands
Activities on Operands
 
C programming Lab 2
C programming Lab 2C programming Lab 2
C programming Lab 2
 
Plsql programs
Plsql programsPlsql programs
Plsql programs
 
Cinfo
CinfoCinfo
Cinfo
 
Write a program that accepts percentage from the user and displays its grade ...
Write a program that accepts percentage from the user and displays its grade ...Write a program that accepts percentage from the user and displays its grade ...
Write a program that accepts percentage from the user and displays its grade ...
 
Factorial Program in C
Factorial Program in CFactorial Program in C
Factorial Program in C
 
Template matching
Template matchingTemplate matching
Template matching
 
Basic of c programming www.eakanchha.com
Basic of c programming www.eakanchha.comBasic of c programming www.eakanchha.com
Basic of c programming www.eakanchha.com
 
Introduction to Computer and Programing - Lecture 04
Introduction to Computer and Programing - Lecture 04Introduction to Computer and Programing - Lecture 04
Introduction to Computer and Programing - Lecture 04
 
Exp 3-2 d422 (1)
Exp 3-2  d422 (1)Exp 3-2  d422 (1)
Exp 3-2 d422 (1)
 
Lecture 8 increment_and_decrement_operators
Lecture 8 increment_and_decrement_operatorsLecture 8 increment_and_decrement_operators
Lecture 8 increment_and_decrement_operators
 
Scope of variable
Scope of variableScope of variable
Scope of variable
 
C Language Programs
C Language Programs C Language Programs
C Language Programs
 
C Programming Language Part 7
C Programming Language Part 7C Programming Language Part 7
C Programming Language Part 7
 

Viewers also liked

Design Thinking Approach to Online Engagement (Full Version)
Design Thinking Approach to Online Engagement (Full Version)Design Thinking Approach to Online Engagement (Full Version)
Design Thinking Approach to Online Engagement (Full Version)Cloud View Pte Ltd
 
It activity 6.3 catapults
It activity 6.3 catapultsIt activity 6.3 catapults
It activity 6.3 catapultslibbyheli
 
データセンターコンファレンス2014Spring_Niscom
データセンターコンファレンス2014Spring_Niscomデータセンターコンファレンス2014Spring_Niscom
データセンターコンファレンス2014Spring_NiscomTakeshi Mitsuishi
 
ソーシャルメディア仕事術 vol.1
ソーシャルメディア仕事術 vol.1ソーシャルメディア仕事術 vol.1
ソーシャルメディア仕事術 vol.1新一 佐藤
 
Lab exe 2 dti 2143 dam31303
Lab exe 2 dti 2143 dam31303Lab exe 2 dti 2143 dam31303
Lab exe 2 dti 2143 dam31303alish sha
 
Presentatie Altijd Mooi en Altijd Mooi Natuurlijk
Presentatie Altijd Mooi en Altijd Mooi NatuurlijkPresentatie Altijd Mooi en Altijd Mooi Natuurlijk
Presentatie Altijd Mooi en Altijd Mooi NatuurlijkAltijdMooi
 
UNI-Joint Story Telling
UNI-Joint Story TellingUNI-Joint Story Telling
UNI-Joint Story Tellingstoryofxu
 
Profileer jezelf met social media
Profileer jezelf met social mediaProfileer jezelf met social media
Profileer jezelf met social mediaTom van den Berg
 
Metabolismo 2009 2010 new
Metabolismo 2009 2010 newMetabolismo 2009 2010 new
Metabolismo 2009 2010 newjuanapardo
 
Henry's open mind
Henry's open mindHenry's open mind
Henry's open mindnplisko
 
Tectonic Processes and Landscapes
Tectonic Processes and LandscapesTectonic Processes and Landscapes
Tectonic Processes and Landscapesjess2011
 
การนำเสนอ..
การนำเสนอ..การนำเสนอ..
การนำเสนอ..NattAA
 
Natalia_Tarabanova_cmf2013
Natalia_Tarabanova_cmf2013Natalia_Tarabanova_cmf2013
Natalia_Tarabanova_cmf2013Evgeny Vasyuk
 

Viewers also liked (20)

Design Thinking Approach to Online Engagement (Full Version)
Design Thinking Approach to Online Engagement (Full Version)Design Thinking Approach to Online Engagement (Full Version)
Design Thinking Approach to Online Engagement (Full Version)
 
It activity 6.3 catapults
It activity 6.3 catapultsIt activity 6.3 catapults
It activity 6.3 catapults
 
データセンターコンファレンス2014Spring_Niscom
データセンターコンファレンス2014Spring_Niscomデータセンターコンファレンス2014Spring_Niscom
データセンターコンファレンス2014Spring_Niscom
 
žYdėjimas
žYdėjimasžYdėjimas
žYdėjimas
 
ソーシャルメディア仕事術 vol.1
ソーシャルメディア仕事術 vol.1ソーシャルメディア仕事術 vol.1
ソーシャルメディア仕事術 vol.1
 
Lab exe 2 dti 2143 dam31303
Lab exe 2 dti 2143 dam31303Lab exe 2 dti 2143 dam31303
Lab exe 2 dti 2143 dam31303
 
Presentatie Altijd Mooi en Altijd Mooi Natuurlijk
Presentatie Altijd Mooi en Altijd Mooi NatuurlijkPresentatie Altijd Mooi en Altijd Mooi Natuurlijk
Presentatie Altijd Mooi en Altijd Mooi Natuurlijk
 
UNI-Joint Story Telling
UNI-Joint Story TellingUNI-Joint Story Telling
UNI-Joint Story Telling
 
Awsをつかってみた
AwsをつかってみたAwsをつかってみた
Awsをつかってみた
 
Profileer jezelf met social media
Profileer jezelf met social mediaProfileer jezelf met social media
Profileer jezelf met social media
 
Metabolismo 2009 2010 new
Metabolismo 2009 2010 newMetabolismo 2009 2010 new
Metabolismo 2009 2010 new
 
ОГЭ - 2015
ОГЭ - 2015ОГЭ - 2015
ОГЭ - 2015
 
Henry's open mind
Henry's open mindHenry's open mind
Henry's open mind
 
Tectonic Processes and Landscapes
Tectonic Processes and LandscapesTectonic Processes and Landscapes
Tectonic Processes and Landscapes
 
การนำเสนอ..
การนำเสนอ..การนำเสนอ..
การนำเสนอ..
 
Fracciones+algebraicas (3ºeso 4º eso)
Fracciones+algebraicas (3ºeso  4º eso)Fracciones+algebraicas (3ºeso  4º eso)
Fracciones+algebraicas (3ºeso 4º eso)
 
Natalia_Tarabanova_cmf2013
Natalia_Tarabanova_cmf2013Natalia_Tarabanova_cmf2013
Natalia_Tarabanova_cmf2013
 
mettalurgy-12th sci cbse
mettalurgy-12th sci cbsemettalurgy-12th sci cbse
mettalurgy-12th sci cbse
 
Puc Iu
Puc IuPuc Iu
Puc Iu
 
Pop
PopPop
Pop
 

Similar to Dti2143 lab sheet 6

Dti2143 lab sheet 9
Dti2143 lab sheet 9Dti2143 lab sheet 9
Dti2143 lab sheet 9alish sha
 
Bti1022 lab sheet 9 10
Bti1022 lab sheet 9 10Bti1022 lab sheet 9 10
Bti1022 lab sheet 9 10alish sha
 
CS4200 2019 | Lecture 2 | syntax-definition
CS4200 2019 | Lecture 2 | syntax-definitionCS4200 2019 | Lecture 2 | syntax-definition
CS4200 2019 | Lecture 2 | syntax-definitionEelco Visser
 
Compiler Construction | Lecture 2 | Declarative Syntax Definition
Compiler Construction | Lecture 2 | Declarative Syntax DefinitionCompiler Construction | Lecture 2 | Declarative Syntax Definition
Compiler Construction | Lecture 2 | Declarative Syntax DefinitionEelco Visser
 
Qust & ans inc
Qust & ans incQust & ans inc
Qust & ans incnayakq
 
Bti1022 lab sheet 3
Bti1022 lab sheet 3Bti1022 lab sheet 3
Bti1022 lab sheet 3alish sha
 
Dti2143 lab sheet 8
Dti2143 lab sheet 8Dti2143 lab sheet 8
Dti2143 lab sheet 8alish 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.docxjacksnathalie
 
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 .docxtrappiteboni
 
PROVIDE COMMENTS TO FELLOW STUDENTS ANSWERS AND PLEASE DON’T SAY G.docx
PROVIDE COMMENTS TO FELLOW STUDENTS ANSWERS AND PLEASE DON’T SAY G.docxPROVIDE COMMENTS TO FELLOW STUDENTS ANSWERS AND PLEASE DON’T SAY G.docx
PROVIDE COMMENTS TO FELLOW STUDENTS ANSWERS AND PLEASE DON’T SAY G.docxamrit47
 
Bti1022 lab sheet 8
Bti1022 lab sheet 8Bti1022 lab sheet 8
Bti1022 lab sheet 8alish sha
 
Bti1022 lab sheet 8
Bti1022 lab sheet 8Bti1022 lab sheet 8
Bti1022 lab sheet 8alish sha
 
Programming fundamental 02
Programming fundamental 02Programming fundamental 02
Programming fundamental 02Suhail Akraam
 
JLK Chapter 5 – Methods and ModularityDRAFT January 2015 Edition.docx
JLK Chapter 5 – Methods and ModularityDRAFT January 2015 Edition.docxJLK Chapter 5 – Methods and ModularityDRAFT January 2015 Edition.docx
JLK Chapter 5 – Methods and ModularityDRAFT January 2015 Edition.docxvrickens
 

Similar to Dti2143 lab sheet 6 (20)

Dti2143 lab sheet 9
Dti2143 lab sheet 9Dti2143 lab sheet 9
Dti2143 lab sheet 9
 
Bti1022 lab sheet 9 10
Bti1022 lab sheet 9 10Bti1022 lab sheet 9 10
Bti1022 lab sheet 9 10
 
CS4200 2019 | Lecture 2 | syntax-definition
CS4200 2019 | Lecture 2 | syntax-definitionCS4200 2019 | Lecture 2 | syntax-definition
CS4200 2019 | Lecture 2 | syntax-definition
 
Compiler Construction | Lecture 2 | Declarative Syntax Definition
Compiler Construction | Lecture 2 | Declarative Syntax DefinitionCompiler Construction | Lecture 2 | Declarative Syntax Definition
Compiler Construction | Lecture 2 | Declarative Syntax Definition
 
Qust & ans inc
Qust & ans incQust & ans inc
Qust & ans inc
 
Bti1022 lab sheet 3
Bti1022 lab sheet 3Bti1022 lab sheet 3
Bti1022 lab sheet 3
 
C important questions
C important questionsC important questions
C important questions
 
Array Cont
Array ContArray Cont
Array Cont
 
Dti2143 lab sheet 8
Dti2143 lab sheet 8Dti2143 lab sheet 8
Dti2143 lab sheet 8
 
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
 
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
 
PROVIDE COMMENTS TO FELLOW STUDENTS ANSWERS AND PLEASE DON’T SAY G.docx
PROVIDE COMMENTS TO FELLOW STUDENTS ANSWERS AND PLEASE DON’T SAY G.docxPROVIDE COMMENTS TO FELLOW STUDENTS ANSWERS AND PLEASE DON’T SAY G.docx
PROVIDE COMMENTS TO FELLOW STUDENTS ANSWERS AND PLEASE DON’T SAY G.docx
 
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
 
C code examples
C code examplesC code examples
C code examples
 
Programming fundamental 02
Programming fundamental 02Programming fundamental 02
Programming fundamental 02
 
17 Jo P May 08
17 Jo P May 0817 Jo P May 08
17 Jo P May 08
 
Code optimization
Code optimization Code optimization
Code optimization
 
Code optimization
Code optimization Code optimization
Code optimization
 
JLK Chapter 5 – Methods and ModularityDRAFT January 2015 Edition.docx
JLK Chapter 5 – Methods and ModularityDRAFT January 2015 Edition.docxJLK Chapter 5 – Methods and ModularityDRAFT January 2015 Edition.docx
JLK Chapter 5 – Methods and ModularityDRAFT January 2015 Edition.docx
 

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 9alish 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) - sharifahalish 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) - sharifahalish 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_13alish sha
 
Lab 10 sem ii_12_13
Lab 10 sem ii_12_13Lab 10 sem ii_12_13
Lab 10 sem ii_12_13alish sha
 
Lab 5 2012/2012
Lab 5 2012/2012Lab 5 2012/2012
Lab 5 2012/2012alish sha
 
Purpose elaborate
Purpose elaboratePurpose elaborate
Purpose elaboratealish sha
 
Test 1 alish schema 1
Test 1 alish schema 1Test 1 alish schema 1
Test 1 alish schema 1alish sha
 
Lab 6 sem ii_11_12
Lab 6 sem ii_11_12Lab 6 sem ii_11_12
Lab 6 sem ii_11_12alish sha
 
Test 1 skema q&a
Test 1 skema q&aTest 1 skema q&a
Test 1 skema q&aalish sha
 
Test 1 skema q&a
Test 1 skema q&aTest 1 skema q&a
Test 1 skema q&aalish sha
 
Final project
Final projectFinal project
Final projectalish sha
 
Final project
Final projectFinal project
Final projectalish sha
 
Attn list test
Attn list testAttn list test
Attn list testalish sha
 
Carry markdam31303
Carry markdam31303Carry markdam31303
Carry markdam31303alish 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
 

Dti2143 lab sheet 6