From eb85145551b2429487e688b1d65ce85d601e0a4f Mon Sep 17 00:00:00 2001 From: munyebenjr Date: Thu, 12 Apr 2018 13:12:31 +0300 Subject: [PATCH 1/2] Add files via upload --- QUESTION 4.c | 31 +++++++++++++++++++++++++++++++ SOLUTION 1.cpp | 12 ++++++++++++ SOLUTION 2.c | 18 ++++++++++++++++++ SOLUTION 3.c | 22 ++++++++++++++++++++++ 4 files changed, 83 insertions(+) create mode 100644 QUESTION 4.c create mode 100644 SOLUTION 1.cpp create mode 100644 SOLUTION 2.c create mode 100644 SOLUTION 3.c diff --git a/QUESTION 4.c b/QUESTION 4.c new file mode 100644 index 00000000..c265922a --- /dev/null +++ b/QUESTION 4.c @@ -0,0 +1,31 @@ +/* solution to question four*/ +void addarrays(int array1[], int array2[],int destination_array[],int size) +{ + + for(int i=0;i +int*addarrays(int array1[], int array2[],int size); +int main() +{ + + int array1[]={1,5,3,22,6}; + int array2[]={13,143,11,10,121}; + int*array3=addarrays(array1,array2,5); + for(int i=0;i<5;i++){ + printf("%d",array3[i]) + } +} +int*addarrays(int array1[],int array2[],int len) +{ + int*destination_array=malloc(len*sizeof(int)); + for(inti=0;i + int x=1; +main(void) +{ + + if(x==1){ + printf("x equals 1");} + else{ + printf("x doesnt equal 1");} + return 0; +} diff --git a/SOLUTION 2.c b/SOLUTION 2.c new file mode 100644 index 00000000..d6c06c7d --- /dev/null +++ b/SOLUTION 2.c @@ -0,0 +1,18 @@ +/* Answer for a header file for do_it()*/ +#ifndef DO_IT_H +#define DO_IT_H + +float do_it(char a, char b, char c) + +#endif//DO_IT_H +/* Answer for a header for a function print_a_number()*/ +#ifndef PRINT_A_NUMBER_H +#definr PRINT_A_NUMBER_H + +void print_a_number(int x) +#endif//PRINT_A_NUMBER_H + +/*Answer for finding whats wrong with the program*/ + The print_msg() function is not supposed to take any arguments but the + main function calls it with a string argument. + diff --git a/SOLUTION 3.c b/SOLUTION 3.c new file mode 100644 index 00000000..13abb6bf --- /dev/null +++ b/SOLUTION 3.c @@ -0,0 +1,22 @@ +/* SOLUTION TO QUESTION 3 */ +long array[50]; // DECLARATION FOR AN ARRAY THAT WILL HOLD 50 TYPE LONG VALUES +long array[49]=123456;// STATEMENT THAT ASSIGNS 123.456 AS 50TH ELEMENT IN THE ABOVE ARRAY +for(x=0;x<100;x++)// THE VALUES OF X WILL BE 0 TO 99 WHEN THE "FOR" STATEMENT IS COMPLETE +for(ctr=2;ctr<10;ctr+=3)// THE VALUE OF ctr WILL BE 8 WHEN THE STATEMENT IS COMPLETED + + + +/* WHILE STATEMENT THAT COUNTS FROM 1 TO 100 IN STEPS OF 3*/ +# include + main(void) + { + int count=1; +while(count<=100){ + printf("%d",counter); + count+=3; +} +} + +// PROBLEM WITH THE CODE +for (counter=1;counter Date: Thu, 12 Apr 2018 13:15:15 +0300 Subject: [PATCH 2/2] Create MY DETAILS --- MY DETAILS | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 MY DETAILS diff --git a/MY DETAILS b/MY DETAILS new file mode 100644 index 00000000..d712afee --- /dev/null +++ b/MY DETAILS @@ -0,0 +1,3 @@ +# NAME:MUNYE BEN +# REG NO:16/U/7601/PS +# COURSE BSC ELECTRICAL ENGINEERING