• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Dti2143 dam31303 lab sheet 8
 

Dti2143 dam31303 lab sheet 8

on

  • 498 views

 

Statistics

Views

Total Views
498
Views on SlideShare
498
Embed Views
0

Actions

Likes
0
Downloads
32
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Microsoft Word

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Dti2143 dam31303 lab sheet 8 Dti2143 dam31303 lab sheet 8 Document Transcript

    • 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 />
      • Examples:main(), getio(), calc(), disp()
      • the output should be similar as:
      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 />
      • Reprogram the coding above to:
      • Input 12 number
      • Calculate total
      • Calculate Average