Download presentation
Presentation is loading. Please wait.
1
1 Array Knowledge Understand the execute technique of array Skill Can write application program using one and two dimensional array
2
2 Why Array? Assume that you were asked to write a program that accept 10 student marks, calculating average mark, and then print a number of students that get more than average mark. How to store all these marks?
3
#include void main() { int mark1, mark2, mark3, mark4, mark5, mark6, mark7, mark8, mark9, mark10; int bil=0, total_mark = 0; float Average_mark; printf(“\nRead 10 test marks : \n”); scanf(“%d%d%d%d%d%d%d%d%d%d”, &mark1, &mark2, &mark3, &mark4, &mark5, &mark6, &mark7, &mark8, &mark9, &mark10); total_mark = mark1 + mark2 + mark3 + mark4 +mark5 + mark6 + mark7 + mark8 + mark9 + mark10; Average_mark = (float) total_mark/10; Read student marks Solving Without Using Array
4
#include void main() { int mark1, mark2, mark3, mark4, mark5, mark6, mark7, mark8, mark9, mark10; int bil=0, total_mark = 0; float Average_mark; printf(“\nRead 10 test marks : \n”); scanf(“%d%d%d%d%d%d%d%d%d%d”, &mark1, &mark2, &mark3, &mark4, &mark5, &mark6, &mark7, &mark8, &mark9, &mark10); total_mark = mark1 + mark2 + mark3 + mark4 +mark5 + mark6 + mark7 + mark8 + mark9 + mark10; Average_mark = (float) total_mark/10; Calculate the total mark
5
Solving Without Using Array Calculate the average mark #include void main() { int mark1, mark2, mark3, mark4, mark5, mark6, mark7, mark8, mark9, mark10; int bil=0, total_mark = 0; float Average_mark; printf(“\nRead 10 test marks : \n”); scanf(“%d%d%d%d%d%d%d%d%d%d”, &mark1, &mark2, &mark3, &mark4, &mark5, &mark6, &mark7, &mark8, &mark9, &mark10); total_mark = mark1 + mark2 + mark3 + mark4 +mark5 + mark6 + mark7 + mark8 + mark9 + mark10; Average_mark = (float) total_mark/10;
6
if (mark1 > Average_mark) bil++; if (mark2 > Average_mark) bil++; if (mark3 > Average_mark) bil++; if (mark4 > Average_mark) bil++; if (mark5 > Average_mark) bil++; if (mark6 > Average_mark) bil++; if (mark7 > Average_mark) bil++; if (mark8 > Average_mark) bil++; if (mark9 > Average_mark) bil++; if (mark10 > Average_mark) bil++; printf(“\nAverage mark = %.2f”, purata); printf(“\n Number of students that get more than Average mark %d”, bil); } What would happen if there were 100 students? Solving Without Using Array Calculate number of students which get more than Average mark
7
Solving Without Using Array if (mark1 > Average_mark) bil++; if (mark2 > Average_mark) bil++; if (mark3 > Average_mark) bil++; if (mark4 > Average_mark) bil++; if (mark5 > Average_mark) bil++; if (mark6 > Average_mark) bil++; if (mark7 > Average_mark) bil++; if (mark8 > Average_mark) bil++; if (mark9 > Average_mark) bil++; if (mark10 > Average_mark) bil++; printf(“\nAverage mark = %.2f”, Average_mark); printf(“\n Number of students that get more than average mark = %d”, bil); } What would happen if there were 100 students? Print the result
8
8 One-dimensional Array Instead of using 10 variables to represent 10 student marks,another technique is using one-dimensional array for storing a list of marks. Array is a collection of memory location that is used for storing data from same type. Each memory location in array is referred by array’s name and location memory index.
9
9 One Dimensional Array 67 mark 34 76 47 82 54 38 72 63 24 [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] For printing each mark in array: for (i=0; i < 10; i++) printf("%d ", mark[i]) Array name
10
10 One Dimensional Array 67 mark 34 76 47 82 54 38 72 63 24 [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] For printing each mark in array: for (i=0; i < 10; i++) printf("%d ", mark[i]) Array Index
11
11 One-Dimensional Array Array declaration syntax data_type name_of_array[integer_expression]; Example: int mark[10]; In C programming, each index in array is start from 0. Thus, the last index number in one array of sized n is n-1.
12
12 Array Controlling One way for giving initial value to array’s element is giving a list of initial value in array declaration.
13
13 Array Controlling Example: int month[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; month 31 28 30 31 30 31 [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] 30 31 [10] [11]
14
14 Array Controlling If the list of initial value is less than array size, the rest element will be given 0 value int month[12] = { 31, 28, 31, 30, 31 } month 31 28 30 0 31 0 0 0 0 [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] 0 0 [10] [11]
15
15 Array Controlling Array size can be ignore in declaration if it is given by initial value list. Array size will be set based on a number of data in their list. int month[ ] = { 31, 28, 31, 30, 31 } month 31 28 30 31 [0] [1] [2] [3] [4]
16
16 Array Assignment Value assignment to array’s element is same as value assign to variable. Assignment to array can be done element by element.
17
17 Array Assignment Example: tinggi ??? [0] [1] [2] [3] [4] float tinggi[5]; tinggi[0] = 31.34; tinggi[1] = 28.11; tinggi[2] = 31.25; tinggi[3] = 30.94; tinggi[4] = 31.68;
18
18 Array Assignment tinggi 31.34 ??? [0] [1] [2] [3] [4] float tinggi[5]; tinggi[0] = 31.34; tinggi[1] = 28.11; tinggi[2] = 31.25; tinggi[3] = 30.94; tinggi[4] = 31.68; Example:
19
19 Array Assignment tinggi 31.34 ??? 28.11 ??? [0] [1] [2] [3] [4] float tinggi[5]; tinggi[0] = 31.34; tinggi[1] = 28.11; tinggi[2] = 31.25; tinggi[3] = 30.94; tinggi[4] = 31.68; Example:
20
20 Array Assignment tinggi 31.34 31.25 28.11 ??? [0] [1] [2] [3] [4] float tinggi[5]; tinggi[0] = 31.34; tinggi[1] = 28.11; tinggi[2] = 31.25; tinggi[3] = 30.94; tinggi[4] = 31.68; Example:
21
21 Array Assignment tinggi 31.34 31.25 28.11 30.94 ??? [0] [1] [2] [3] [4] float tinggi[5]; tinggi[0] = 31.34; tinggi[1] = 28.11; tinggi[2] = 31.25; tinggi[3] = 30.94; tinggi[4] = 31.68; Example:
22
22 Array Assignment tinggi 31.34 31.25 28.11 30.94 31.68 [0] [1] [2] [3] [4] float tinggi[5]; tinggi[0] = 31.34; tinggi[1] = 28.11; tinggi[2] = 31.25; tinggi[3] = 30.94; tinggi[4] = 31.68; Example:
23
23 Array Assignment In certain situation, array assignment can be write using looping. number ??? [0] [1] [2] [3] [4] i ??? int number[5], i; for (i=0; i < 5; i++) number[i] = 0;
24
24 Array Assignment In certain situation, array assignment can be write using looping number ??? [0] [1] [2] [3] [4] i 0 int number[5], i; for (i=0; i < 5; i++) number[i] = 0;
25
25 Array Assignment In certain situation, array assignment can be write using looping. number ??? [0] [1] [2] [3] [4] i 0 int number[5], i; for (i=0; i < 5; i++) number[i] = 0; 0<5 TRUE
26
26 Array Assignment In certain situation, array assignment can be write using looping. number 0 ??? [0] [1] [2] [3] [4] i 0 int number[5], i; for (i=0; i < 5; i++) number[i] = 0;
27
27 Array Assignment In certain situation, array assignment can be write using looping. number 0 ??? [0] [1] [2] [3] [4] i 1 int number[5], i; for (i=0; i < 5; i++) number[i] = 0;
28
28 Array Assignment In certain situation, array assignment can be write using looping. number 0 ??? [0] [1] [2] [3] [4] i 1 int number[5], i; for (i=0; i < 5; i++) number[i] = 0; 1<5 TRUE
29
29 Array Assignment In certain situation, array assignment can be write using looping. number 0 ??? 0 [0] [1] [2] [3] [4] i 1 int number[5], i; for (i=0; i < 5; i++) number[i] = 0;
30
30 Array Assignment In certain situation, array assignment can be write using looping. number 0 ??? 0 [0] [1] [2] [3] [4] i 2 int number[5], i; for (i=0; i < 5; i++) number[i] = 0;
31
31 Array Assignment In certain situation, array assignment can be write using looping. number 0 ??? 0 [0] [1] [2] [3] [4] i 2 int number[5], i; for (i=0; i < 5; i++) number[i] = 0; 2<5 TRUE
32
32 Array Assignment In certain situation, array assignment can be write using looping. number 0 0 0 ??? [0] [1] [2] [3] [4] i 2 int number[5], i; for (i=0; i < 5; i++) number[i] = 0;
33
33 Array Assignment In certain situation, array assignment can be write using looping. number 0 0 0 ??? [0] [1] [2] [3] [4] i 3 int number[5], i; for (i=0; i < 5; i++) number[i] = 0;
34
34 Array Assignment In certain situation, array assignment can be write using looping. number 0 0 0 ??? [0] [1] [2] [3] [4] i 3 int number[5], i; for (i=0; i < 5; i++) number[i] = 0; 3<5 TRUE
35
35 Array Assignment In certain situation, array assignment can be write using looping. number 0 0 0 0 ??? [0] [1] [2] [3] [4] i 3 int number[5], i; for (i=0; i < 5; i++) number[i] = 0;
36
36 Array Assignment In certain situation, array assignment can be write using looping. number 0 0 0 0 ??? [0] [1] [2] [3] [4] i 4 int number[5], i; for (i=0; i < 5; i++) number[i] = 0;
37
37 Array Assignment In certain situation, array assignment can be write using looping. number 0 0 0 0 ??? [0] [1] [2] [3] [4] i 4 int number[5], i; for (i=0; i < 5; i++) number[i] = 0; 4<5 TRUE
38
38 Array Assignment In certain situation, array assignment can be write using looping. number 0 0 0 0 0 [0] [1] [2] [3] [4] i 4 int number[5], i; for (i=0; i < 5; i++) number[i] = 0;
39
39 Array Assignment In certain situation, array assignment can be write using looping. number 0 0 0 0 0 [0] [1] [2] [3] [4] i 5 int number[5], i; for (i=0; i < 5; i++) number[i] = 0;
40
40 Array Assignment In certain situation, array assignment can be write using looping. number 0 0 0 0 0 [0] [1] [2] [3] [4] int number[5], i; for (i=0; i < 5; i++) number[i] = 0; i 5 5<5 FALSE
41
41 Array Assignment In certain situation, array assignment can be write using looping. number 0 0 0 0 0 [0] [1] [2] [3] [4] int number[5], i; for (i=0; i < 5; i++) number[i] = 0; i 5
42
42 Example of Using Array Program to process 3 student mark Read students mark Calculate number of mark greater than Average mark Calculate Total mark All Students mark Calculate Average mark All Students mark Total mark Total mark Average mark All students Mark, Average mark number Print the result Average mark, number
43
Example of Using Array #include void main() { int mark[3], i, bil, total_mark; float Average_mark; for (i = 0; i < 3, i++) { printf(“Enter mark %d : “, i); scanf(“%d”, &mark[i]); } total_mark= 0; for (i = 0; i < 3; i++) total_mark += mark[i]; Average_mark = (float) total_mark / 3; bil = 0; for (i = 0; i < 3; i++ ) if (mark[i] > Average_mark) bil++; printf(“\nAverage mark= %.2f”, Average_mark); printf(“\nNumber of students that get more than average mark = %d\n”, bil); } Read student marks
44
Example of Using Array #include void main() { int mark[3], i, bil, total_mark; float Average_mark; for (i = 0; i < 3, i++) { printf(“Enter mark %d : “, i); scanf(“%d”, &mark[i]); } total_mark= 0; for (i = 0; i < 3; i++) total_mark += mark[i]; Average_mark = (float) total_mark / 3; bil = 0; for (i = 0; i < 3; i++ ) if (mark[i] > Average_mark) bil++; printf(“\nAverage mark= %.2f”, Average_mark); printf(“\nNumber of students that get more than average mark = %d\n”, bil); } Calculate total mark
45
Example of Using Array #include void main() { int mark[3], i, bil, total_mark; float Average_mark; for (i = 0; i < 3, i++) { printf(“Enter mark %d : “, i); scanf(“%d”, &mark[i]); } total_mark= 0; for (i = 0; i < 3; i++) total_mark += mark[i]; Average_mark = (float) total_mark / 3; bil = 0; for (i = 0; i < 3; i++ ) if (mark[i] > Average_mark) bil++; printf(“\nAverage mark= %.2f”, Average_mark); printf(“\nNumber of students that get more than average mark = %d\n”, bil); } Calculate the average mark
46
#include void main() { int mark[3], i, bil, total_mark; float Average_mark; for (i = 0; i < 3, i++) { printf(“Enter mark %d : “, i); scanf(“%d”, &mark[i]); } total_mark= 0; for (i = 0; i < 3; i++) total_mark += mark[i]; Average_mark = (float) total_mark / 3; bil = 0; for (i = 0; i < 3; i++ ) if (mark[i] > Average_mark) bil++; printf(“\nAverage mark= %.2f”, Average_mark); printf(“\nNumber of students that get more than average mark = %d\n”, bil); } Example of Using Array Calculate the number of student that get more than average mark
47
Example of Using Array #include void main() { int mark[3], i, bil, total_mark; float Average_mark; for (i = 0; i < 3, i++) { printf(“Enter mark %d : “, i); scanf(“%d”, &mark[i]); } total_mark= 0; for (i = 0; i < 3; i++) total_mark += mark[i]; Average_mark = (float) total_mark / 3; bil = 0; for (i = 0; i < 3; i++ ) if (mark[i] > Average_mark) bil++; printf(“\nAverage mark= %.2f”, Average_mark); printf(“\nNumber of students that get more than average mark = %d\n”, bil); } Print the result
48
Example of Using Array #include void main() { int mark[3], i, bil, total_mark; float Average_mark; for (i = 0; i < 3, i++) { printf(“Enter mark %d : “, i); scanf(“%d”, &mark[i]); } total_mark= 0; for (i = 0; i < 3; i++) total_mark += mark[i]; Average_mark = (float) total_mark / 3; bil = 0; for (i = 0; i < 3; i++ ) if (mark[i] > Average_mark) bil++; printf(“\nAverage mark= %.2f”, Average_mark); printf(“\nNumber of mark that are greater than average = %d\n”, bil); } ??? i bil total_mark Average_mark [0] [1] [2] mark
49
#include void main() { int mark[3], i, bil, total_mark; float Average_mark; for (i = 0; i < 3, i++) { printf(“Enter mark %d : “, i); scanf(“%d”, &mark[i]); } total_mark= 0; for (i = 0; i < 3; i++) total_mark += mark[i]; Average_mark = (float) total_mark / 3; bil = 0; for (i = 0; i < 3; i++ ) if (mark[i] > Average_mark) bil++; printf(“\nAverage mark= %.2f”, Average_mark); printf(“\nNumber of mark that are greater than average = %d\n”, bil); } Example of Using Array 0 ??? i bil total_mark Average_mark [0] [1] [2] mark
50
#include void main() { int mark[3], i, bil, total_mark; float Average_mark; for (i = 0; i < 3, i++) { printf(“Enter mark %d : “, i); scanf(“%d”, &mark[i]); } total_mark= 0; for (i = 0; i < 3; i++) total_mark += mark[i]; Average_mark = (float) total_mark / 3; bil = 0; for (i = 0; i < 3; i++ ) if (mark[i] > Average_mark) bil++; printf(“\nAverage mark= %.2f”, Average_mark); printf(“\nNumber of mark that are greater than average = %d\n”, bil); } Example of Using Array 0 ??? i bil total_mark Average_mark [0] [1] [2] mark 0<3 TRUE
51
#include void main() { int mark[3], i, bil, total_mark; float Average_mark; for (i = 0; i < 3, i++) { printf(“Enter mark %d : “, i); scanf(“%d”, &mark[i]); } total_mark= 0; for (i = 0; i < 3; i++) total_mark += mark[i]; Average_mark = (float) total_mark / 3; bil = 0; for (i = 0; i < 3; i++ ) if (mark[i] > Average_mark) bil++; printf(“\nAverage mark= %.2f”, Average_mark); printf(“\nNumber of mark that are greater than average = %d\n”, bil); } Example of Using Array 0 ??? 70 ??? Enter mark 0: 70 _ i bil total_mark Average_mark [0] [1] [2] mark
52
#include void main() { int mark[3], i, bil, total_mark; float Average_mark; for (i = 0; i < 3, i++) { printf(“Enter mark %d : “, i); scanf(“%d”, &mark[i]); } total_mark= 0; for (i = 0; i < 3; i++) total_mark += mark[i]; Average_mark = (float) total_mark / 3; bil = 0; for (i = 0; i < 3; i++ ) if (mark[i] > Average_mark) bil++; printf(“\nAverage mark= %.2f”, Average_mark); printf(“\nNumber of mark that are greater than average = %d\n”, bil); } Example of Using Array 1 ??? 70 ??? Enter mark 0: 70 _ i bil total_mark Average_mark [0] [1] [2] mark
53
#include void main() { int mark[3], i, bil, total_mark; float Average_mark; for (i = 0; i < 3, i++) { printf(“Enter mark %d : “, i); scanf(“%d”, &mark[i]); } total_mark= 0; for (i = 0; i < 3; i++) total_mark += mark[i]; Average_mark = (float) total_mark / 3; bil = 0; for (i = 0; i < 3; i++ ) if (mark[i] > Average_mark) bil++; printf(“\nAverage mark= %.2f”, Average_mark); printf(“\nNumber of mark that are greater than average = %d\n”, bil); } Example of Using Array 1 ??? 70 ??? Enter mark 0: 70 i bil total_mark Average_mark [0] [1] [2] mark 1<3 TRUE
54
#include void main() { int mark[3], i, bil, total_mark; float Average_mark; for (i = 0; i < 3, i++) { printf(“Enter mark %d : “, i); scanf(“%d”, &mark[i]); } total_mark= 0; for (i = 0; i < 3; i++) total_mark += mark[i]; Average_mark = (float) total_mark / 3; bil = 0; for (i = 0; i < 3; i++ ) if (mark[i] > Average_mark) bil++; printf(“\nAverage mark= %.2f”, Average_mark); printf(“\nNumber of mark that are greater than average = %d\n”, bil); } Example of Using Array 1 ??? 70 30 ??? Enter mark 0: 70 Enter mark 1: 30 i bil total_mark Average_mark [0] [1] [2] mark
55
#include void main() { int mark[3], i, bil, total_mark; float Average_mark; for (i = 0; i < 3, i++) { printf(“Enter mark %d : “, i); scanf(“%d”, &mark[i]); } total_mark= 0; for (i = 0; i < 3; i++) total_mark += mark[i]; Average_mark = (float) total_mark / 3; bil = 0; for (i = 0; i < 3; i++ ) if (mark[i] > Average_mark) bil++; printf(“\nAverage mark= %.2f”, Average_mark); printf(“\nNumber of mark that are greater than average = %d\n”, bil); } Example of Using Array 2 ??? 70 30 ??? Enter mark 0: 70 Enter mark 1: 30 _ i bil total_mark Average_mark [0] [1] [2] mark
56
#include void main() { int mark[3], i, bil, total_mark; float Average_mark; for (i = 0; i < 3, i++) { printf(“Enter mark %d : “, i); scanf(“%d”, &mark[i]); } total_mark= 0; for (i = 0; i < 3; i++) total_mark += mark[i]; Average_mark = (float) total_mark / 3; bil = 0; for (i = 0; i < 3; i++ ) if (mark[i] > Average_mark) bil++; printf(“\nAverage mark= %.2f”, Average_mark); printf(“\nNumber of mark that are greater than average = %d\n”, bil); } Example of Using Array 2 ??? 70 30 ??? Enter mark 0: 70 Enter mark 1: 30 _ i bil total_mark Average_mark [0] [1] [2] mark 2<3 TRUE
57
#include void main() { int mark[3], i, bil, total_mark; float Average_mark; for (i = 0; i < 3, i++) { printf(“Enter mark %d : “, i); scanf(“%d”, &mark[i]); } total_mark= 0; for (i = 0; i < 3; i++) total_mark += mark[i]; Average_mark = (float) total_mark / 3; bil = 0; for (i = 0; i < 3; i++ ) if (mark[i] > Average_mark) bil++; printf(“\nAverage mark= %.2f”, Average_mark); printf(“\nNumber of mark that are greater than average = %d\n”, bil); } Example of Using Array 2 ??? 70 30 80 Enter mark 0: 70 Enter mark 1: 30 Enter mark 2: 80 _ i bil total_mark Average_mark [0] [1] [2] mark
58
#include void main() { int mark[3], i, bil, total_mark; float Average_mark; for (i = 0; i < 3, i++) { printf(“Enter mark %d : “, i); scanf(“%d”, &mark[i]); } total_mark= 0; for (i = 0; i < 3; i++) total_mark += mark[i]; Average_mark = (float) total_mark / 3; bil = 0; for (i = 0; i < 3; i++ ) if (mark[i] > Average_mark) bil++; printf(“\nAverage mark= %.2f”, Average_mark); printf(“\nNumber of mark that are greater than average = %d\n”, bil); } Example of Using Array 3 ??? 70 30 80 Enter mark 0: 70 Enter mark 1: 30 Enter mark 2: 80 _ i bil total_mark Average_mark [0] [1] [2] mark
59
#include void main() { int mark[3], i, bil, total_mark; float Average_mark; for (i = 0; i < 3, i++) { printf(“Enter mark %d : “, i); scanf(“%d”, &mark[i]); } total_mark= 0; for (i = 0; i < 3; i++) total_mark += mark[i]; Average_mark = (float) total_mark / 3; bil = 0; for (i = 0; i < 3; i++ ) if (mark[i] > Average_mark) bil++; printf(“\nAverage mark= %.2f”, Average_mark); printf(“\nNumber of mark that are greater than average = %d\n”, bil); } Example of Using Array 3 ??? 70 30 80 Enter mark 0: 70 Enter mark 1: 30 Enter mark 2: 80 _ i bil total_mark Average_mark [0] [1] [2] mark 3<3 FALSE
60
#include void main() { int mark[3], i, bil, total_mark; float Average_mark; for (i = 0; i < 3, i++) { printf(“Enter mark %d : “, i); scanf(“%d”, &mark[i]); } total_mark= 0; for (i = 0; i < 3; i++) total_mark += mark[i]; Average_mark = (float) total_mark / 3; bil = 0; for (i = 0; i < 3; i++ ) if (mark[i] > Average_mark) bil++; printf(“\nAverage mark= %.2f”, Average_mark); printf(“\nNumber of mark that are greater than average = %d\n”, bil); } Example of Using Array 3 ??? 0 70 30 80 Enter mark 0: 70 Enter mark 1: 30 Enter mark 2: 80 _ i bil total_mark Average_mark [0] [1] [2] mark
61
#include void main() { int mark[3], i, bil, total_mark; float Average_mark; for (i = 0; i < 3, i++) { printf(“Enter mark %d : “, i); scanf(“%d”, &mark[i]); } total_mark= 0; for (i = 0; i < 3; i++) total_mark += mark[i]; Average_mark = (float) total_mark / 3; bil = 0; for (i = 0; i < 3; i++ ) if (mark[i] > Average_mark) bil++; printf(“\nAverage mark= %.2f”, Average_mark); printf(“\nNumber of mark that are greater than average = %d\n”, bil); } Example of Using Array 0 ??? 0 70 30 80 Enter mark 0: 70 Enter mark 1: 30 Enter mark 2: 80 _ i bil total_mark Average_mark [0] [1] [2] mark
62
#include void main() { int mark[3], i, bil, total_mark; float Average_mark; for (i = 0; i < 3, i++) { printf(“Enter mark %d : “, i); scanf(“%d”, &mark[i]); } total_mark= 0; for (i = 0; i < 3; i++) total_mark += mark[i]; Average_mark = (float) total_mark / 3; bil = 0; for (i = 0; i < 3; i++ ) if (mark[i] > Average_mark) bil++; printf(“\nAverage mark= %.2f”, Average_mark); printf(“\nNumber of students that get more than average mark = %d\n”, bil); } Example of Using Array 0 ??? 0 70 30 80 Enter mark 0: 70 Enter mark 1: 30 Enter mark 2: 80 _ i bil total_mark Average_mark [0] [1] [2] mark 0<3 TRUE
63
#include void main() { int mark[3], i, bil, total_mark; float Average_mark; for (i = 0; i < 3, i++) { printf(“Enter mark %d : “, i); scanf(“%d”, &mark[i]); } total_mark= 0; for (i = 0; i < 3; i++) total_mark += mark[i]; Average_mark = (float) total_mark / 3; bil = 0; for (i = 0; i < 3; i++ ) if (mark[i] > Average_mark) bil++; printf(“\nAverage mark= %.2f”, Average_mark); printf(“\nNumber of students that get more than average mark = %d\n”, bil); } Example of Using Array 0 ??? 70 ??? 70 30 80 Enter mark 0: 70 Enter mark 1: 30 Enter mark 2: 80 _ i bil total_mark Average_mark [0] [1] [2] mark
64
#include void main() { int mark[3], i, bil, total_mark; float Average_mark; for (i = 0; i < 3, i++) { printf(“Enter mark %d : “, i); scanf(“%d”, &mark[i]); } total_mark= 0; for (i = 0; i < 3; i++) total_mark += mark[i]; Average_mark = (float) total_mark / 3; bil = 0; for (i = 0; i < 3; i++ ) if (mark[i] > Average_mark) bil++; printf(“\nAverage mark= %.2f”, Average_mark); printf(“\nNumber of students that get more than average mark = %d\n”, bil); } Example of Using Array 1 ??? 70 ??? 70 30 80 Enter mark 0: 70 Enter mark 1: 30 Enter mark 2: 80 _ i bil total_mark Average_mark [0] [1] [2] mark
65
#include void main() { int mark[3], i, bil, total_mark; float Average_mark; for (i = 0; i < 3, i++) { printf(“Enter mark %d : “, i); scanf(“%d”, &mark[i]); } total_mark= 0; for (i = 0; i < 3; i++) total_mark += mark[i]; Average_mark = (float) total_mark / 3; bil = 0; for (i = 0; i < 3; i++ ) if (mark[i] > Average_mark) bil++; printf(“\nAverage mark= %.2f”, Average_mark); printf(“\nNumber of students that get more than average mark = %d\n”, bil); } Example of Using Array 1 ??? 70 ??? 70 30 80 Enter mark 0: 70 Enter mark 1: 30 Enter mark 2: 80 _ i bil total_mark Average_mark [0] [1] [2] mark 1<3 TRUE
66
#include void main() { int mark[3], i, bil, total_mark; float Average_mark; for (i = 0; i < 3, i++) { printf(“Enter mark %d : “, i); scanf(“%d”, &mark[i]); } total_mark= 0; for (i = 0; i < 3; i++) total_mark += mark[i]; Average_mark = (float) total_mark / 3; bil = 0; for (i = 0; i < 3; i++ ) if (mark[i] > Average_mark) bil++; printf(“\nAverage mark= %.2f”, Average_mark); printf(“\nNumber of students that get more than average mark = %d\n”, bil); } Example of Using Array 1 ??? 100 ??? 70 30 80 Enter mark 0: 70 Enter mark 1: 30 Enter mark 2: 80 _ i bil total_mark Average_mark [0] [1] [2] mark
67
#include void main() { int mark[3], i, bil, total_mark; float Average_mark; for (i = 0; i < 3, i++) { printf(“Enter mark %d : “, i); scanf(“%d”, &mark[i]); } total_mark= 0; for (i = 0; i < 3; i++) total_mark += mark[i]; Average_mark = (float) total_mark / 3; bil = 0; for (i = 0; i < 3; i++ ) if (mark[i] > Average_mark) bil++; printf(“\nAverage mark= %.2f”, Average_mark); printf(“\nNumber of students that get more than average mark = %d\n”, bil); } Example of Using Array 2 ??? 100 ??? 70 30 80 Enter mark 0: 70 Enter mark 1: 30 Enter mark 2: 80 _ i bil total_mark Average_mark [0] [1] [2] mark
68
#include void main() { int mark[3], i, bil, total_mark; float Average_mark; for (i = 0; i < 3, i++) { printf(“Enter mark %d : “, i); scanf(“%d”, &mark[i]); } total_mark= 0; for (i = 0; i < 3; i++) total_mark += mark[i]; Average_mark = (float) total_mark / 3; bil = 0; for (i = 0; i < 3; i++ ) if (mark[i] > Average_mark) bil++; printf(“\nAverage mark= %.2f”, Average_mark); printf(“\nNumber of students that get more than average mark = %d\n”, bil); } Example of Using Array 2 ??? 100 ??? 70 30 80 Enter mark 0: 70 Enter mark 1: 30 Enter mark 2: 80 _ i bil total_mark Average_mark [0] [1] [2] mark 2<3 TRUE
69
#include void main() { int mark[3], i, bil, total_mark; float Average_mark; for (i = 0; i < 3, i++) { printf(“Enter mark %d : “, i); scanf(“%d”, &mark[i]); } total_mark= 0; for (i = 0; i < 3; i++) total_mark += mark[i]; Average_mark = (float) total_mark / 3; bil = 0; for (i = 0; i < 3; i++ ) if (mark[i] > Average_mark) bil++; printf(“\nAverage mark= %.2f”, Average_mark); printf(“\nNumber of students that get more than average mark = %d\n”, bil); } Example of Using Array 2 ??? 180 ??? 70 30 80 Enter mark 0: 70 Enter mark 1: 30 Enter mark 2: 80 _ i bil total_mark Average_mark [0] [1] [2] mark
70
#include void main() { int mark[3], i, bil, total_mark; float Average_mark; for (i = 0; i < 3, i++) { printf(“Enter mark %d : “, i); scanf(“%d”, &mark[i]); } total_mark= 0; for (i = 0; i < 3; i++) total_mark += mark[i]; Average_mark = (float) total_mark / 3; bil = 0; for (i = 0; i < 3; i++ ) if (mark[i] > Average_mark) bil++; printf(“\nAverage mark= %.2f”, Average_mark); printf(“\nNumber of students that get more than average mark = %d\n”, bil); } Example of Using Array 3 ??? 180 ??? 70 30 80 Enter mark 0: 70 Enter mark 1: 30 Enter mark 2: 80 _ i bil total_mark Average_mark [0] [1] [2] mark
71
#include void main() { int mark[3], i, bil, total_mark; float Average_mark; for (i = 0; i < 3, i++) { printf(“Enter mark %d : “, i); scanf(“%d”, &mark[i]); } total_mark= 0; for (i = 0; i < 3; i++) total_mark += mark[i]; Average_mark = (float) total_mark / 3; bil = 0; for (i = 0; i < 3; i++ ) if (mark[i] > Average_mark) bil++; printf(“\nAverage mark= %.2f”, Average_mark); printf(“\nNumber of students that get more than average mark = %d\n”, bil); } Example of Using Array 3 ??? 180 ??? 70 30 80 Enter mark 0: 70 Enter mark 1: 30 Enter mark 2: 80 _ i bil total_mark Average_mark [0] [1] [2] mark 3<3 FALSE
72
#include void main() { int mark[3], i, bil, total_mark; float Average_mark; for (i = 0; i < 3, i++) { printf(“Enter mark %d : “, i); scanf(“%d”, &mark[i]); } total_mark= 0; for (i = 0; i < 3; i++) total_mark += mark[i]; Average_mark = (float) total_mark / 3; bil = 0; for (i = 0; i < 3; i++ ) if (mark[i] > Average_mark) bil++; printf(“\nAverage mark= %.2f”, Average_mark); printf(“\nNumber of students that get more than average mark = %d\n”, bil); } Example of Using Array 3 ??? 180 60.00 70 30 80 Enter mark 0: 70 Enter mark 1: 30 Enter mark 2: 80 _ i bil total_mark Average_mark [0] [1] [2] mark
73
#include void main() { int mark[3], i, bil, total_mark; float Average_mark; for (i = 0; i < 3, i++) { printf(“Enter mark %d : “, i); scanf(“%d”, &mark[i]); } total_mark= 0; for (i = 0; i < 3; i++) total_mark += mark[i]; Average_mark = (float) total_mark / 3; bil = 0; for (i = 0; i < 3; i++ ) if (mark[i] > Average_mark) bil++; printf(“\nAverage mark= %.2f”, Average_mark); printf(“\nNumber of students that get more than average mark = %d\n”, bil); } Example of Using Array 3 0 180 60.00 70 30 80 Enter mark 0: 70 Enter mark 1: 30 Enter mark 2: 80 _ i bil total_mark Average_mark [0] [1] [2] mark
74
#include void main() { int mark[3], i, bil, total_mark; float Average_mark; for (i = 0; i < 3, i++) { printf(“Enter mark %d : “, i); scanf(“%d”, &mark[i]); } total_mark= 0; for (i = 0; i < 3; i++) total_mark += mark[i]; Average_mark = (float) total_mark / 3; bil = 0; for (i = 0; i < 3; i++ ) if (mark[i] > Average_mark) bil++; printf(“\nAverage mark= %.2f”, Average_mark); printf(“\nNumber of students that get more than average mark = %d\n”, bil); } Example of Using Array 0 0 180 60.00 70 30 80 Enter mark 0: 70 Enter mark 1: 30 Enter mark 2: 80 _ i bil total_mark Average_mark [0] [1] [2] mark
75
#include void main() { int mark[3], i, bil, total_mark; float Average_mark; for (i = 0; i < 3, i++) { printf(“Enter mark %d : “, i); scanf(“%d”, &mark[i]); } total_mark= 0; for (i = 0; i < 3; i++) total_mark += mark[i]; Average_mark = (float) total_mark / 3; bil = 0; for (i = 0; i < 3; i++ ) if (mark[i] > Average_mark) bil++; printf(“\nAverage mark= %.2f”, Average_mark); printf(“\nNumber of students that get more than average mark = %d\n”, bil); } Example of Using Array 0 0 180 60.00 70 30 80 Enter mark 0: 70 Enter mark 1: 30 Enter mark 2: 80 _ i bil total_mark Average_mark [0] [1] [2] mark 0<3 TRUE
76
#include void main() { int mark[3], i, bil, total_mark; float Average_mark; for (i = 0; i < 3, i++) { printf(“Enter mark %d : “, i); scanf(“%d”, &mark[i]); } total_mark= 0; for (i = 0; i < 3; i++) total_mark += mark[i]; Average_mark = (float) total_mark / 3; bil = 0; for (i = 0; i < 3; i++ ) if (mark[i] > Average_mark) bil++; printf(“\nAverage mark= %.2f”, Average_mark); printf(“\nNumber of students that get more than average mark = %d\n”, bil); } Example of Using Array 0 0 180 60.00 70 30 80 Enter mark 0: 70 Enter mark 1: 30 Enter mark 2: 80 _ i bil total_mark Average_mark [0] [1] [2] mark
77
#include void main() { int mark[3], i, bil, total_mark; float Average_mark; for (i = 0; i < 3, i++) { printf(“Enter mark %d : “, i); scanf(“%d”, &mark[i]); } total_mark= 0; for (i = 0; i < 3; i++) total_mark += mark[i]; Average_mark = (float) total_mark / 3; bil = 0; for (i = 0; i < 3; i++ ) if (mark[i] > Average_mark) bil++; printf(“\nAverage mark= %.2f”, Average_mark); printf(“\nNumber of students that get more than average mark = %d\n”, bil); Example of Using Array 0 1 180 60.00 70 30 80 Enter mark 0: 70 Enter mark 1: 30 Enter mark 2: 80 _ i bil total_mark Average_mark [0] [1] [2] mark
78
#include void main() { int mark[3], i, bil, total_mark; float Average_mark; for (i = 0; i < 3, i++) { printf(“Enter mark %d : “, i); scanf(“%d”, &mark[i]); } total_mark= 0; for (i = 0; i < 3; i++) total_mark += mark[i]; Average_mark = (float) total_mark / 3; bil = 0; for (i = 0; i < 3; i++ ) if (mark[i] > Average_mark) bil++; printf(“\nAverage mark= %.2f”, Average_mark); printf(“\nNumber of students that get more than average mark = %d\n”, bil); } Example of Using Array 1 1 180 60.00 70 30 80 Enter mark 0: 70 Enter mark 1: 30 Enter mark 2: 80 _ i bil total_mark Average_mark [0] [1] [2] mark
79
#include void main() { int mark[3], i, bil, total_mark; float Average_mark; for (i = 0; i < 3, i++) { printf(“Enter mark %d : “, i); scanf(“%d”, &mark[i]); } total_mark= 0; for (i = 0; i < 3; i++) total_mark += mark[i]; Average_mark = (float) total_mark / 3; bil = 0; for (i = 0; i < 3; i++ ) if (mark[i] > Average_mark) bil++; printf(“\nAverage mark= %.2f”, Average_mark); printf(“\nNumber of students that get more than average mark = %d\n”, bil); } Example of Using Array 1 1 180 60.00 70 30 80 Enter mark 0: 70 Enter mark 1: 30 Enter mark 2: 80 _ i bil total_mark Average_mark [0] [1] [2] mark 1<3 TRUE
80
#include void main() { int mark[3], i, bil, total_mark; float Average_mark; for (i = 0; i < 3, i++) { printf(“Enter mark %d : “, i); scanf(“%d”, &mark[i]); } total_mark= 0; for (i = 0; i < 3; i++) total_mark += mark[i]; Average_mark = (float) total_mark / 3; bil = 0; for (i = 0; i < 3; i++ ) if (mark[i] > Average_mark) bil++; printf(“\nAverage mark= %.2f”, Average_mark); printf(“\nNumber of students that get more than average mark = %d\n”, bil); } Example of Using Array 1 1 180 60.00 70 30 80 Enter mark 0: 70 Enter mark 1: 30 Enter mark 2: 80 _ i bil total_mark Average_mark [0] [1] [2] mark
81
#include void main() { int mark[3], i, bil, total_mark; float Average_mark; for (i = 0; i < 3, i++) { printf(“Enter mark %d : “, i); scanf(“%d”, &mark[i]); } total_mark= 0; for (i = 0; i < 3; i++) total_mark += mark[i]; Average_mark = (float) total_mark / 3; bil = 0; for (i = 0; i < 3; i++ ) if (mark[i] > Average_mark) bil++; printf(“\nAverage mark= %.2f”, Average_mark); printf(“\nNumber of students that get more than average mark = %d\n”, bil); } Example of Using Array 2 1 180 60.00 70 30 80 Enter mark 0: 70 Enter mark 1: 30 Enter mark 2: 80 _ i bil total_mark Average_mark [0] [1] [2] mark
82
#include void main() { int mark[3], i, bil, total_mark; float Average_mark; for (i = 0; i < 3, i++) { printf(“Enter mark %d : “, i); scanf(“%d”, &mark[i]); } total_mark= 0; for (i = 0; i < 3; i++) total_mark += mark[i]; Average_mark = (float) total_mark / 3; bil = 0; for (i = 0; i < 3; i++ ) if (mark[i] > Average_mark) bil++; printf(“\nAverage mark= %.2f”, Average_mark); printf(“\nNumber of students that get more than average mark = %d\n”, bil); } Example of Using Array 2 1 180 60.00 70 30 80 Enter mark 0: 70 Enter mark 1: 30 Enter mark 2: 80 _ i bil total_mark Average_mark [0] [1] [2] mark 2<3 TRUE
83
#include void main() { int mark[3], i, bil, total_mark; float Average_mark; for (i = 0; i < 3, i++) { printf(“Enter mark %d : “, i); scanf(“%d”, &mark[i]); } total_mark= 0; for (i = 0; i < 3; i++) total_mark += mark[i]; Average_mark = (float) total_mark / 3; bil = 0; for (i = 0; i < 3; i++ ) if (mark[i] > Average_mark) bil++; printf(“\nAverage mark= %.2f”, Average_mark); printf(“\nNumber of students that get more than average mark = %d\n”, bil); } Example of Using Array 2 1 180 60.00 70 30 80 Enter mark 0: 70 Enter mark 1: 30 Enter mark 2: 80 _ i bil total_mark Average_mark [0] [1] [2] mark
84
#include void main() { int mark[3], i, bil, total_mark; float Average_mark; for (i = 0; i < 3, i++) { printf(“Enter mark %d : “, i); scanf(“%d”, &mark[i]); } total_mark= 0; for (i = 0; i < 3; i++) total_mark += mark[i]; Average_mark = (float) total_mark / 3; bil = 0; for (i = 0; i < 3; i++ ) if (mark[i] > Average_mark) bil++; printf(“\nAverage mark= %.2f”, Average_mark); printf(“\nNumber of students that get more than average mark = %d\n”, bil); } Example of Using Array 2 2 180 60.00 70 30 80 Enter mark 0: 70 Enter mark 1: 30 Enter mark 2: 80 _ i bil total_mark Average_mark [0] [1] [2] mark
85
#include void main() { int mark[3], i, bil, total_mark; float Average_mark; for (i = 0; i < 3, i++) { printf(“Enter mark %d : “, i); scanf(“%d”, &mark[i]); } total_mark= 0; for (i = 0; i < 3; i++) total_mark += mark[i]; Average_mark = (float) total_mark / 3; bil = 0; for (i = 0; i < 3; i++ ) if (mark[i] > Average_mark) bil++; printf(“\nAverage mark= %.2f”, Average_mark); printf(“\nNumber of students that get more than average mark = %d\n”, bil); } Example of Using Array 3 2 180 60.00 70 30 80 Enter mark 0: 70 Enter mark 1: 30 Enter mark 2: 80 _ i bil total_mark Average_mark [0] [1] [2] mark
86
86 #include void main() { int mark[3], i, bil, total_mark; float Average_mark; for (i = 0; i < 3, i++) { printf(“Enter mark %d : “, i); scanf(“%d”, &mark[i]); } total_mark= 0; for (i = 0; i < 3; i++) total_mark += mark[i]; Average_mark = (float) total_mark / 3; bil = 0; for (i = 0; i < 3; i++ ) if (mark[i] > Average_mark) bil++; printf(“\nAverage mark= %.2f”, Average_mark); printf(“\nNumber of students that get more than average mark = %d\n”, bil); } Example of Using Array 3 2 180 60.00 70 30 80 Enter mark 0: 70 Enter mark 1: 30 Enter mark 2: 80 _ i bil total_mark Average_mark [0] [1] [2] mark 3<3 FALSE
87
87 #include void main() { int mark[3], i, bil, total_mark; float Average_mark; for (i = 0; i < 3, i++) { printf(“Enter mark %d : “, i); scanf(“%d”, &mark[i]); } total_mark= 0; for (i = 0; i < 3; i++) total_mark += mark[i]; Average_mark = (float) total_mark / 3; bil = 0; for (i = 0; i < 3; i++ ) if (mark[i] > Average_mark) bil++; printf(“\nAverage mark= %.2f”, Average_mark); printf(“\nNumber of students that get more than average mark = %d\n”, bil); } Example of Using Array 3 2 180 60.00 70 30 80 Enter mark 0: 70 Enter mark 1: 30 Enter mark 2: 80 Average mark= 60.00 Number of students that get more than average mark = 2 _ i bil total_mark Average_mark [0] [1] [2] mark
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.