More Related Content
Similar to Bti1022 lab sheet 8
Similar to Bti1022 lab sheet 8 (20)
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 />