Upcoming SlideShare
×

# Dti2143 dam31303 lab sheet 8

521 views

Published on

0 Likes
Statistics
Notes
• Full Name
Comment goes here.

Are you sure you want to Yes No
• Be the first to comment

• Be the first to like this

Views
Total views
521
On SlideShare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
34
0
Likes
0
Embeds 0
No embeds

No notes for slide

### Dti2143 dam31303 lab sheet 8

1. 1. left0UNIVERSITI TUN HUSSEIN ONN MALAYSIA<br />FACULTY OF MECHANICAL AND MANUFACTURING ENGINEERING <br />DTI 2143: COMPUTER PROGRAMMING<br />LAB EXERCISE 7 FUNCTION, GOTO & ARRAY introLAB EXERCISE 7 FUNCTION, GOTO & ARRAY intro<br />Exercise 1.0:<br />Write a program to calculate student’s mark. Section the program with function. <br /><ul><li>Examples:main(), getio(), calc(), disp()
2. 2. the output should be similar as:</li></ul>Exercise 2.0:<br />Type in the following program<br />#include<stdio.h><br />#include<conio.h><br />int main()<br />{<br />char choco,macs,chmc,lagi;<br /> printf("tt Testing the goto functionnn");<br />mula: <br /> <br /> printf("n Do you like to eat chocolate(enter y or n): ");<br /> scanf("%s", &choco);<br /> <br /> if(choco=='y')<br /> goto chocs;<br /> else<br /> goto mcd; <br /> <br />chocs:<br /> printf("n Do you love chocolate more than McD? (enter y or n): ");<br /> scanf("%s", &chmc);<br /> if(chmc=='y')<br /> goto chocos;<br /> else<br /> goto mcd; <br /> <br />mcd:<br /> printf("n Do you really love McD? (enter y or n): ");<br /> scanf("%s", &macs);<br /> if(macs=='y')<br /> goto mcdees;<br /> else<br /> goto proud; <br />proud:<br /> printf("n You should be proud. Eat more healthy food");<br /> goto lagi; <br />chocos:<br /> printf("n You should be proud. you help yourself by consuming anticancer, brain stimulator, cough preventor and antidiarrhoeal food ");<br /> goto lagi; <br />mcdees: <br /> printf("n You should try to control yourself before it is to late. n STOP eating fatty food"); <br />lagi: <br /> printf ("nn Again? (y to continue): ");<br /> scanf ("%s",&lagi);<br /> if(lagi=='y')<br /> goto mula;<br /> else<br /> printf(" Thank you for using this system"); <br /> <br /> getch();<br /> return 0;<br />}<br />Study program 2.0 carefully, then compile and execute it.<br />3.1 Rewrite this program to example GOTO function based on your own understanding.<br />Exercise 3.0: Compile and run the program below<br />#include<stdio.h><br />#include<conio.h><br />int main(){<br />int i,j;<br />float b[3][4]={1.1,2.2,3.3,4.4,5.5,6.6,7.7,8.8,9.9,10.1,11.1,12.1};<br />for(i=0;i<3;i++)<br />{<br /> for(j=0;j<4;j++)<br /> {<br /> printf("[%d][%d]=%.1fn",i,j,b[i][j]); <br /> } <br />}<br />getch();<br />return 0; <br />}<br /><ul><li>Reprogram the coding above to:
3. 3. Input 12 number
4. 4. Calculate total
5. 5. Calculate Average