SlideShare a Scribd company logo
1 of 4
left0UNIVERSITI TUN HUSSEIN ONN MALAYSIA<br />FACULTY OF MECHANICAL AND MANUFACTURING ENGINEERING <br />BTI 1022: COMPUTER PROGRAMMING<br />LAB EXERCISE 7 LOOP DESIGN<br />Study the design below<br />For Loopfor (int i = 1; i <= n; i++){   double interest = balance * rate / 100;   balance = balance + interest;}While Loop<br />Exercise 1:<br />Draw a flow chart for:<br />for (int item=0;item<7;item++){<br />    printf(quot;
 Enter price of item: RMquot;
);<br />    scanf(quot;
%lfquot;
, &price);<br />    totalprice +=price;<br />}<br />Exercise 2:<br />Draw a flow chart for:<br />int bil, nilai = 3;<br />for (bil = 5; bil >0; bil--){    <br />         if( bil % 2 == 1)<br />               printf(quot;
 %dquot;
, bil + nilai); <br />   }<br />Exercise 3:<br />Draw a flow chart for:<br />int x = 1;  <br /> while ( x < 10 ) { <br /> printf( quot;
%dquot;
, x );<br />}<br />Exercise 4:<br />Draw a flow chart for:<br />int row,space,star;<br />for(row=1;row<=9;row++)<br />{                     <br />      for(space=8;space>=row;space--)<br />    {<br />       printf(quot;
%cquot;
,288); };<br />           for (star=1;star<row;star++)<br />       {<br />        printf(quot;
* quot;
);  }<br />                       <br />printf(quot;
quot;
);}<br />Exercise 5: Write an run this program from compiler <br />#include<stdio.h><br />#include<conio.h><br />char matrik[20],nama[50];<br />float kiratotal(float x, float y, float z){<br />      float a;<br />      a=x+y+z;<br />      return a;<br />      }<br />float kirapurata(float b){<br />     <br />      return (b/3);<br />      }<br />      <br />      <br />int display (float total, float average){<br />printf(quot;
=========================quot;
);<br />printf(quot;
     STUDENT'S RESULTquot;
);<br />printf(quot;
=========================quot;
);<br />    printf(quot;
name:%squot;
,nama);<br />    printf(quot;
matrix number:%squot;
,matrik);<br />    printf(quot;
total:%.2fquot;
,total);<br />    printf(quot;
average:%.2fquot;
,average);<br />    <br />    if (average<=100 && average>=80)<br />    { printf(quot;
grade:Aquot;
,average); }<br />     else if (average<=79 && average>=60)<br />    { printf(quot;
grade:Bquot;
,average); }<br />      else if (average<=59 && average>=40)<br />    {  printf(quot;
grade:cquot;
,average); }<br />      else if (average<=39 && average>=20)<br />    { printf(quot;
grade:Dquot;
,average); }<br />       else if (average<=19 && average>=0)<br />    { printf(quot;
grade:Equot;
,average);}<br />        <br />        <br />        <br />}<br />int main()<br />{<br />float total,average,test,assign,final;<br />char ulang='y';<br />while (ulang=='y')<br />{<br />printf(quot;
Enter student informationquot;
);<br />printf(quot;
----------------------------quot;
);<br />printf(quot;
Matrik No. : quot;
); scanf(quot;
%squot;
,&matrik);<br />printf(quot;
Name : quot;
); scanf(quot;
%squot;
,&nama);//gets(nama);<br />printf(quot;
Test Mark : quot;
); scanf(quot;
%fquot;
,&test);<br />printf(quot;
Assignment Mark : quot;
); scanf(quot;
%fquot;
,&assign);<br />printf(quot;
Final Exam Mark : quot;
); scanf(quot;
%fquot;
,&final);<br />total= kiratotal(test, assign, final);<br />average= kirapurata(total);<br />display(total,average);<br />    printf(quot;
=========================quot;
);     <br />    printf (quot;
Do you want to proceed? Enter 'y' for yes or else for no : quot;
);<br />    scanf (quot;
%squot;
,&ulang);<br />    printf (quot;
quot;
);<br />}<br />getch();<br />return 0;<br />}<br />
Bti1022 lab sheet 8
Bti1022 lab sheet 8
Bti1022 lab sheet 8

More Related Content

What's hot (14)

Spiral array
Spiral arraySpiral array
Spiral array
 
Prefix Postfix
Prefix PostfixPrefix Postfix
Prefix Postfix
 
1 (1)
1 (1)1 (1)
1 (1)
 
Math hquickissential
Math hquickissentialMath hquickissential
Math hquickissential
 
Muzzammilrashid
MuzzammilrashidMuzzammilrashid
Muzzammilrashid
 
week-17x
week-17xweek-17x
week-17x
 
C PROGRAMS
C PROGRAMSC PROGRAMS
C PROGRAMS
 
week-6x
week-6xweek-6x
week-6x
 
C Language Programs
C Language Programs C Language Programs
C Language Programs
 
Program presentation
Program presentationProgram presentation
Program presentation
 
Data Structure - 2nd Study
Data Structure - 2nd StudyData Structure - 2nd Study
Data Structure - 2nd Study
 
C workshop day 6
C workshop day 6C workshop day 6
C workshop day 6
 
Lecture 8 increment_and_decrement_operators
Lecture 8 increment_and_decrement_operatorsLecture 8 increment_and_decrement_operators
Lecture 8 increment_and_decrement_operators
 
Runge kutta C programme
Runge kutta C programmeRunge kutta C programme
Runge kutta C programme
 

Viewers also liked

Bti1022 lab sheet 3
Bti1022 lab sheet 3Bti1022 lab sheet 3
Bti1022 lab sheet 3alish sha
 
Rediscover india
Rediscover indiaRediscover india
Rediscover indiaIkjot Sodhi
 
Workplace violence by Brad Hyde
Workplace violence by Brad HydeWorkplace violence by Brad Hyde
Workplace violence by Brad HydeBrad Hyde
 
Maxim_Mozgovoy_Lamoda_cmf2013
Maxim_Mozgovoy_Lamoda_cmf2013Maxim_Mozgovoy_Lamoda_cmf2013
Maxim_Mozgovoy_Lamoda_cmf2013Evgeny Vasyuk
 
Câu chuyệ sức khoẻ 21
Câu chuyệ sức khoẻ 21Câu chuyệ sức khoẻ 21
Câu chuyệ sức khoẻ 21vinhtungdk
 
Rèdais & IED_Gokcek
Rèdais & IED_GokcekRèdais & IED_Gokcek
Rèdais & IED_GokcekRèdais
 
Los secretos de las presentaciones de Steve Jobs
Los secretos de las presentaciones de Steve JobsLos secretos de las presentaciones de Steve Jobs
Los secretos de las presentaciones de Steve JobsDavid Aguirre
 
Developing The Mongolian Wolf Spirit In Football
Developing The Mongolian Wolf Spirit In FootballDeveloping The Mongolian Wolf Spirit In Football
Developing The Mongolian Wolf Spirit In FootballMichele Ferraris
 
โครงงานครั้งที่ 2 (Guava Cake)
โครงงานครั้งที่ 2 (Guava Cake)โครงงานครั้งที่ 2 (Guava Cake)
โครงงานครั้งที่ 2 (Guava Cake)NattAA
 
Rèdais & IED_Razzak
Rèdais & IED_RazzakRèdais & IED_Razzak
Rèdais & IED_RazzakRèdais
 
Chapter02
Chapter02Chapter02
Chapter02Linh Vo
 
Dti2143 chap 4 control structures aka_selection
Dti2143 chap 4 control structures aka_selectionDti2143 chap 4 control structures aka_selection
Dti2143 chap 4 control structures aka_selectionalish sha
 
Tersigni_Ance_24052011
Tersigni_Ance_24052011Tersigni_Ance_24052011
Tersigni_Ance_24052011Rèdais
 
Dti2143 lab sheet 7
Dti2143 lab sheet 7Dti2143 lab sheet 7
Dti2143 lab sheet 7alish sha
 
Presentation1
Presentation1Presentation1
Presentation1scorbi2
 

Viewers also liked (20)

Bti1022 lab sheet 3
Bti1022 lab sheet 3Bti1022 lab sheet 3
Bti1022 lab sheet 3
 
Rediscover india
Rediscover indiaRediscover india
Rediscover india
 
Workplace violence by Brad Hyde
Workplace violence by Brad HydeWorkplace violence by Brad Hyde
Workplace violence by Brad Hyde
 
Maxim_Mozgovoy_Lamoda_cmf2013
Maxim_Mozgovoy_Lamoda_cmf2013Maxim_Mozgovoy_Lamoda_cmf2013
Maxim_Mozgovoy_Lamoda_cmf2013
 
Why Choose Us
Why Choose UsWhy Choose Us
Why Choose Us
 
Câu chuyệ sức khoẻ 21
Câu chuyệ sức khoẻ 21Câu chuyệ sức khoẻ 21
Câu chuyệ sức khoẻ 21
 
Rèdais & IED_Gokcek
Rèdais & IED_GokcekRèdais & IED_Gokcek
Rèdais & IED_Gokcek
 
Los secretos de las presentaciones de Steve Jobs
Los secretos de las presentaciones de Steve JobsLos secretos de las presentaciones de Steve Jobs
Los secretos de las presentaciones de Steve Jobs
 
Literary Terms
Literary Terms Literary Terms
Literary Terms
 
Developing The Mongolian Wolf Spirit In Football
Developing The Mongolian Wolf Spirit In FootballDeveloping The Mongolian Wolf Spirit In Football
Developing The Mongolian Wolf Spirit In Football
 
7101 project
7101 project7101 project
7101 project
 
โครงงานครั้งที่ 2 (Guava Cake)
โครงงานครั้งที่ 2 (Guava Cake)โครงงานครั้งที่ 2 (Guava Cake)
โครงงานครั้งที่ 2 (Guava Cake)
 
Question 4
Question 4Question 4
Question 4
 
Rèdais & IED_Razzak
Rèdais & IED_RazzakRèdais & IED_Razzak
Rèdais & IED_Razzak
 
Chapter02
Chapter02Chapter02
Chapter02
 
Dti2143 chap 4 control structures aka_selection
Dti2143 chap 4 control structures aka_selectionDti2143 chap 4 control structures aka_selection
Dti2143 chap 4 control structures aka_selection
 
Vocabulary cards
Vocabulary cardsVocabulary cards
Vocabulary cards
 
Tersigni_Ance_24052011
Tersigni_Ance_24052011Tersigni_Ance_24052011
Tersigni_Ance_24052011
 
Dti2143 lab sheet 7
Dti2143 lab sheet 7Dti2143 lab sheet 7
Dti2143 lab sheet 7
 
Presentation1
Presentation1Presentation1
Presentation1
 

Similar to Bti1022 lab sheet 8 (20)

pointers 1
pointers 1pointers 1
pointers 1
 
VTU Data Structures Lab Manual
VTU Data Structures Lab ManualVTU Data Structures Lab Manual
VTU Data Structures Lab Manual
 
12 lec 12 loop
12 lec 12 loop 12 lec 12 loop
12 lec 12 loop
 
4 operators, expressions &amp; statements
4  operators, expressions &amp; statements4  operators, expressions &amp; statements
4 operators, expressions &amp; statements
 
Bti1022 lab sheet 7
Bti1022 lab sheet 7Bti1022 lab sheet 7
Bti1022 lab sheet 7
 
Cpds lab
Cpds labCpds lab
Cpds lab
 
ADA FILE
ADA FILEADA FILE
ADA FILE
 
Looping
LoopingLooping
Looping
 
Dti2143 chap 4 control statement part 2
Dti2143 chap 4 control statement part 2Dti2143 chap 4 control statement part 2
Dti2143 chap 4 control statement part 2
 
C file
C fileC file
C file
 
An imperative study of c
An imperative study of cAn imperative study of c
An imperative study of c
 
sodapdf-converted into ppt presentation(1).pdf
sodapdf-converted into ppt presentation(1).pdfsodapdf-converted into ppt presentation(1).pdf
sodapdf-converted into ppt presentation(1).pdf
 
Code optimization
Code optimization Code optimization
Code optimization
 
Code optimization
Code optimization Code optimization
Code optimization
 
Cpd lecture im 207
Cpd lecture im 207Cpd lecture im 207
Cpd lecture im 207
 
Paradigmas de Linguagens de Programacao - Aula #4
Paradigmas de Linguagens de Programacao - Aula #4Paradigmas de Linguagens de Programacao - Aula #4
Paradigmas de Linguagens de Programacao - Aula #4
 
Unit 5 Foc
Unit 5 FocUnit 5 Foc
Unit 5 Foc
 
LET US C (5th EDITION) CHAPTER 2 ANSWERS
LET US C (5th EDITION) CHAPTER 2 ANSWERSLET US C (5th EDITION) CHAPTER 2 ANSWERS
LET US C (5th EDITION) CHAPTER 2 ANSWERS
 
Test2
Test2Test2
Test2
 
Bai Giang 11
Bai Giang 11Bai Giang 11
Bai Giang 11
 

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
 

Bti1022 lab sheet 8

  • 1. left0UNIVERSITI TUN HUSSEIN ONN MALAYSIA<br />FACULTY OF MECHANICAL AND MANUFACTURING ENGINEERING <br />BTI 1022: COMPUTER PROGRAMMING<br />LAB EXERCISE 7 LOOP DESIGN<br />Study the design below<br />For Loopfor (int i = 1; i <= n; i++){   double interest = balance * rate / 100;   balance = balance + interest;}While Loop<br />Exercise 1:<br />Draw a flow chart for:<br />for (int item=0;item<7;item++){<br /> printf(quot; Enter price of item: RMquot; );<br /> scanf(quot; %lfquot; , &price);<br /> totalprice +=price;<br />}<br />Exercise 2:<br />Draw a flow chart for:<br />int bil, nilai = 3;<br />for (bil = 5; bil >0; bil--){ <br /> if( bil % 2 == 1)<br /> printf(quot; %dquot; , bil + nilai); <br /> }<br />Exercise 3:<br />Draw a flow chart for:<br />int x = 1; <br /> while ( x < 10 ) { <br /> printf( quot; %dquot; , x );<br />}<br />Exercise 4:<br />Draw a flow chart for:<br />int row,space,star;<br />for(row=1;row<=9;row++)<br />{ <br /> for(space=8;space>=row;space--)<br /> {<br /> printf(quot; %cquot; ,288); };<br /> for (star=1;star<row;star++)<br /> {<br /> printf(quot; * quot; ); }<br /> <br />printf(quot; quot; );}<br />Exercise 5: Write an run this program from compiler <br />#include<stdio.h><br />#include<conio.h><br />char matrik[20],nama[50];<br />float kiratotal(float x, float y, float z){<br /> float a;<br /> a=x+y+z;<br /> return a;<br /> }<br />float kirapurata(float b){<br /> <br /> return (b/3);<br /> }<br /> <br /> <br />int display (float total, float average){<br />printf(quot; =========================quot; );<br />printf(quot; STUDENT'S RESULTquot; );<br />printf(quot; =========================quot; );<br /> printf(quot; name:%squot; ,nama);<br /> printf(quot; matrix number:%squot; ,matrik);<br /> printf(quot; total:%.2fquot; ,total);<br /> printf(quot; average:%.2fquot; ,average);<br /> <br /> if (average<=100 && average>=80)<br /> { printf(quot; grade:Aquot; ,average); }<br /> else if (average<=79 && average>=60)<br /> { printf(quot; grade:Bquot; ,average); }<br /> else if (average<=59 && average>=40)<br /> { printf(quot; grade:cquot; ,average); }<br /> else if (average<=39 && average>=20)<br /> { printf(quot; grade:Dquot; ,average); }<br /> else if (average<=19 && average>=0)<br /> { printf(quot; grade:Equot; ,average);}<br /> <br /> <br /> <br />}<br />int main()<br />{<br />float total,average,test,assign,final;<br />char ulang='y';<br />while (ulang=='y')<br />{<br />printf(quot; Enter student informationquot; );<br />printf(quot; ----------------------------quot; );<br />printf(quot; Matrik No. : quot; ); scanf(quot; %squot; ,&matrik);<br />printf(quot; Name : quot; ); scanf(quot; %squot; ,&nama);//gets(nama);<br />printf(quot; Test Mark : quot; ); scanf(quot; %fquot; ,&test);<br />printf(quot; Assignment Mark : quot; ); scanf(quot; %fquot; ,&assign);<br />printf(quot; Final Exam Mark : quot; ); scanf(quot; %fquot; ,&final);<br />total= kiratotal(test, assign, final);<br />average= kirapurata(total);<br />display(total,average);<br /> printf(quot; =========================quot; ); <br /> printf (quot; Do you want to proceed? Enter 'y' for yes or else for no : quot; );<br /> scanf (quot; %squot; ,&ulang);<br /> printf (quot; quot; );<br />}<br />getch();<br />return 0;<br />}<br />