Dti2143 lab sheet 8

727 views

Published on

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

  • Be the first to like this

No Downloads
Views
Total views
727
On SlideShare
0
From Embeds
0
Number of Embeds
24
Actions
Shares
0
Downloads
36
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Dti2143 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 8 ARRAY<br />Exercise 1.0: Compile and run the program below<br />#include<stdio.h><br />#include<conio.h><br />int main(){<br />int i, mark[10], j=0;<br />printf("Insert 10 Marksn");<br />for(i=0;i<10;i++)<br />{ scanf("%d",&mark[i]);<br /> if(mark[i]>=50)<br /> j++; }<br /> <br />printf("n Total of students passed:%d",j);<br />getch();<br />return 0; <br />}<br /><ul><li> What does the program do
  2. 2. Reprogram the coding above to calculate
  3. 3. Total
  4. 4. Average</li></ul>Exercise 2.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:
  5. 5. Input 12 number
  6. 6. Calculate total
  7. 7. Calculate Average
  8. 8. Exercise 3: Compile and run the program below</li></ul>#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 />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);<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 />3.1 Modify the coding above to get input and output from user in a sub function called getio()<br />

×