Your SlideShare is downloading. ×
Bti1022 lab sheet 8
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Bti1022 lab sheet 8

749

Published on

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
749
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
52
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 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("n Enter price of item: RM");<br /> scanf("%lf", &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("n %d", bil + nilai); <br /> }<br />Exercise 3:<br />Draw a flow chart for:<br />int x = 1; <br /> while ( x < 10 ) { <br /> printf( "%dn", 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("%c",288); };<br /> for (star=1;star<row;star++)<br /> {<br /> printf("* "); }<br /> <br />printf("n");}<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("nn=========================");<br />printf("n STUDENT'S RESULT");<br />printf("n=========================");<br /> printf("nname:%s",nama);<br /> printf("nnmatrix number:%s",matrik);<br /> printf("nntotal:%.2f",total);<br /> printf("nnaverage:%.2fn",average);<br /> <br /> if (average<=100 && average>=80)<br /> { printf("ngrade:A",average); }<br /> else if (average<=79 && average>=60)<br /> { printf("ngrade:B",average); }<br /> else if (average<=59 && average>=40)<br /> { printf("ngrade:c",average); }<br /> else if (average<=39 && average>=20)<br /> { printf("ngrade:D",average); }<br /> else if (average<=19 && average>=0)<br /> { printf("ngrade:E",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("Enter student informationn");<br />printf("----------------------------");<br />printf("nMatrik No. : "); scanf("%s",&matrik);<br />printf("nName : "); scanf("%s",&nama);//gets(nama);<br />printf("nTest Mark : "); scanf("%f",&test);<br />printf("nAssignment Mark : "); scanf("%f",&assign);<br />printf("nFinal Exam Mark : "); scanf("%f",&final);<br />total= kiratotal(test, assign, final);<br />average= kirapurata(total);<br />display(total,average);<br /> printf("n========================="); <br /> printf ("nDo you want to proceed? Enter 'y' for yes or else for no : ");<br /> scanf ("%s",&ulang);<br /> printf ("nnnnn");<br />}<br />getch();<br />return 0;<br />}<br />

×