Monday 18 March 2013

Give 1 example sequences use in computer programming


Sequence in computer programming is the default control structure, instructions are executed one after another. They might, for example, carry out a series of arithmetic operations, assigning results to variables

Example:-
Make a list number of 100 students that attend “seminar keusahawanan”.

Pseudocode
BEGIN
            Declare a list as an array with 100 elements
              for (int student = 0, student<100; student++){
                    list[student] = student + 1 à (arithmetic operation)
                    print list[student]
              }
END

Answer:
No.Student = 0
Print list[student] = 1
No.Student = 1
Print list[student] = 2
.
.
.
.
Print list[student] = 99
No.Student = 100

Source Code
public class sequences {
            public static void main(String[] args) {
             int list [] = new int[100];
            for(int student = 0; student<100; student++) {
                        list[student] = student + 1;
                        System.out.println(list[student]);
                                    }
            }

}

No comments:

Post a Comment