diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json new file mode 100644 index 0000000..1df4412 --- /dev/null +++ b/.vscode/c_cpp_properties.json @@ -0,0 +1,17 @@ +{ + "configurations": [ + { + "name": "Win32", + "includePath": [ + "${workspaceFolder}/**" + ], + "defines": [ + "_DEBUG", + "UNICODE", + "_UNICODE" + ], + "intelliSenseMode": "msvc-x64" + } + ], + "version": 4 +} \ No newline at end of file diff --git a/main.cpp b/main.cpp index f439d60..4159957 100644 --- a/main.cpp +++ b/main.cpp @@ -4,9 +4,23 @@ using namespace std; /** WRITE DOWN YOUR INFORMATION HERE */ -string name = ""; // put your name here -string ID = ""; // put your student id here -int group_id = 0; // your Group Number here (1-8) +/*string name = "HASSAN RIZKY PUTRA SAILELLAH"; // put your name here +string ID = "1301190328"; // put your student id here + +string name = "MUHAMMAD IKRAM KAER SINAPOY"; // put your name here +string ID = "1301193341"; // put your student id here + +string name = "ARPRIANSAH YONATHAN"; // put your name here +string ID = "1301194112"; // put your student id here + +string name = "NAUFAL YOZHA REVANSYAH"; // put your name here +string ID = "1301194282"; // put your student id here + +*/ + +string name = " "; // put your name here +string ID = " "; // put your student id here +int group_id = 1; // your Group Number here (1-8) /** FUNCTIONS LIST, DO NOT MODIFY THESE */ @@ -53,11 +67,24 @@ void insert_sort(int arr[], int &n, int x) { x : number to be inserted */ - // YOUR CODES HERE - //----------------------- + arr[n] = x; + n = n + 1; + + int i, key, j; + for (i = 1; i < n; i++){ + key = arr[i]; + j = i - 1; + while (j >= 0 && arr[j] > key){ + arr[j + 1] = arr[j]; + j = j - 1; + } + arr[j + 1] = key; + } +} + + - //----------------------- } @@ -147,13 +174,20 @@ string count_and_sum(int arr[], int n) { arr : input array n : number of element inside array */ - - // YOUR CODES HERE - //----------------------- - - - //----------------------- + int i, genap, ganjil; + genap = 0; + ganjil = 0; + + for(i = 0; i < n; i++){ + if(arr[i]%2 == 0){ + genap = genap + arr[i]; + } else { + ganjil = ganjil + 1; + } + } + cout << "count odd = " << ganjil << ", sum even = " << genap; return ""; + } @@ -198,7 +232,7 @@ void view_data_1(int arr[], int n) { // YOUR CODES HERE //----------------------- for(int i=0; i