From c200c36e001c1b1fdbaabf282ca4ab051b3a8c8d Mon Sep 17 00:00:00 2001 From: che2109 <33319133+che2109@users.noreply.github.com> Date: Sat, 14 Apr 2018 04:23:38 -0700 Subject: [PATCH 1/4] Create QUESTION 1 --- QUESTION 1 | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 QUESTION 1 diff --git a/QUESTION 1 b/QUESTION 1 new file mode 100644 index 00000000..712c2285 --- /dev/null +++ b/QUESTION 1 @@ -0,0 +1,12 @@ +/* Rwego Ndahiro David +reg no: 16/X/2364/PS*/ +#include +int x = 1; +main() +{ +if(x==1) +printf ("x equals 1"); +else +printf ("x does not equal 1"); +return 0; +} From a854b553c95f42de07d515b6bfd600fa956c5f68 Mon Sep 17 00:00:00 2001 From: che2109 <33319133+che2109@users.noreply.github.com> Date: Sat, 14 Apr 2018 04:25:03 -0700 Subject: [PATCH 2/4] Create QUESTION 2 --- QUESTION 2 | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 QUESTION 2 diff --git a/QUESTION 2 b/QUESTION 2 new file mode 100644 index 00000000..60ab89c7 --- /dev/null +++ b/QUESTION 2 @@ -0,0 +1,20 @@ + +/*Rwego Ndahiro David +Reg No: 16/X/2364/PS +ANSWER OF QUESTION 2: +I) (do_it.h)*/ + +#ifndef DO_IT_H +#define DO_IT_H +float do_it(char x, char y, char z); +#endif // DO_IT_H + +//II) (print_a_number.h) +#ifndef PRINT_A_NUMBER_H +#define PRINT_A_NUMBER_H +void print_a_number(int a); +#endif // PRINT_A_NUMBER_H + +/*iii) + +The print_msg() function shouldn’t take any arguments because the main function calls already have one. */ From 8a8814b9b034319a91c2f80c9cbaacb311201aca Mon Sep 17 00:00:00 2001 From: che2109 <33319133+che2109@users.noreply.github.com> Date: Sat, 14 Apr 2018 04:25:51 -0700 Subject: [PATCH 3/4] Create QUESTION 3 --- QUESTION 3 | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 QUESTION 3 diff --git a/QUESTION 3 b/QUESTION 3 new file mode 100644 index 00000000..434a4767 --- /dev/null +++ b/QUESTION 3 @@ -0,0 +1,28 @@ +// Rwego Ndahiro David +// Reg No: 16/X/2364/PS +//Answers of question 3: +//i) long values[50]; + +//ii) long values[49] = 123.456; + +//iii) x is equal to 99 when the statement is complete + +//iv) The value of ctr is 8 when the statement is complete + + + + +//v) +#include +main(){ +int x = 1; +while(x <= 100){ +//vi) + printf("The value of x : %d\n ", x); + x += 3; +} +} +//Comment: The X will be counted from 1 to 100 by adding 3 + +//vii) We don’t have to put the semicolon to terminate the for loop and the statements for a for loop should be enclosed. + From f61f74884a33b68a7413707c17ff5774d50ced30 Mon Sep 17 00:00:00 2001 From: che2109 <33319133+che2109@users.noreply.github.com> Date: Sat, 14 Apr 2018 04:26:20 -0700 Subject: [PATCH 4/4] Create QUESTION 4 --- QUESTION 4 | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 QUESTION 4 diff --git a/QUESTION 4 b/QUESTION 4 new file mode 100644 index 00000000..17a2f12f --- /dev/null +++ b/QUESTION 4 @@ -0,0 +1,38 @@ +/* Rwego Ndahiro David +Reg No: 16/X/2364/PS*/ +//ANSWERS: +//i) +void addarrays(int array1[], int array2[], int summation_array[], int SIZE) +{ + for(int i=0;i +int *addarrays(int array1[], int array2[], int SIZE); + +main(){ +//iv) +int array1[] = {1,2,3,4,5}; + +int array2[] = {6,7,8,9,10}; + +int *array3 = addarrays(array1, array2, 5); + +for(int i=0;i<5;i++) { +//v) + printf("%d \n", array3[i]); +} +} +int *addarrays(int array1[], int array2[], int length){ + int *destination_array = malloc(length * sizeof(int)); +for(int i=0;i