From 14ff9bfe5939bcadb0e8b4653e2dc2584c8c911f Mon Sep 17 00:00:00 2001 From: DavisTwine <38284972+DavisTwine@users.noreply.github.com> Date: Thu, 12 Apr 2018 09:41:01 +0000 Subject: [PATCH 1/4] QN1 --- Question One.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 Question One.c diff --git a/Question One.c b/Question One.c new file mode 100644 index 00000000..5f99ae51 --- /dev/null +++ b/Question One.c @@ -0,0 +1,15 @@ + /* a program with a fixed bug... */ + #include + int x = 1; + main() + { + if (x == 1){ + printf("x equals 1"); + } + else { + printf("x does not equal to 1");} + return 0; + + } + + From d2b5ba9371d6285d25e9c9c102041452be6c5f72 Mon Sep 17 00:00:00 2001 From: DavisTwine <38284972+DavisTwine@users.noreply.github.com> Date: Thu, 12 Apr 2018 09:45:41 +0000 Subject: [PATCH 2/4] QN.2 --- Question Two .c | 12 ++++++++++++ do_it.h | 6 ++++++ print_a_number.h | 6 ++++++ 3 files changed, 24 insertions(+) create mode 100644 Question Two .c create mode 100644 do_it.h create mode 100644 print_a_number.h diff --git a/Question Two .c b/Question Two .c new file mode 100644 index 00000000..9c217ddb --- /dev/null +++ b/Question Two .c @@ -0,0 +1,12 @@ +#include +void print_msg( void ); +main(){ +print_msg("this is a message to print"); +//the print_msg() function is not supposed to take any arguments but it is being called with a string argument +return 0; +} +void print_msq( void ) //the variable name is wrong,it is supposed to be print_msg instead of print_msq +{ + puts("This is a message to print"); + return 0;//the return 0 statement is not supposed to be there as nothing is meant to be returned +} diff --git a/do_it.h b/do_it.h new file mode 100644 index 00000000..b3d5ecc6 --- /dev/null +++ b/do_it.h @@ -0,0 +1,6 @@ +#ifndef DO_IT_H +#define DO_IT_H + +float do_it(char p,char q,char z); + +#endif diff --git a/print_a_number.h b/print_a_number.h new file mode 100644 index 00000000..6d5e7069 --- /dev/null +++ b/print_a_number.h @@ -0,0 +1,6 @@ +#ifndef PRINT_A_NUMBER_H__ +#define PRINT_A_NUMBER_H__ + +void print_a_number(int y); + +#endif From bc9e51837a810b08e1ee36549d5973617f4eec24 Mon Sep 17 00:00:00 2001 From: DavisTwine <38284972+DavisTwine@users.noreply.github.com> Date: Thu, 12 Apr 2018 09:48:34 +0000 Subject: [PATCH 3/4] QN.3 --- Question Three.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 Question Three.c diff --git a/Question Three.c b/Question Three.c new file mode 100644 index 00000000..33c8a541 --- /dev/null +++ b/Question Three.c @@ -0,0 +1,31 @@ +//Question 3 (a) +long ellarian[50]; + +//Question 3 (b) +ellarian[49] = 123.456; + +//question 3 (c) +for (x = 0); x < 100; x++) +//value of x when the statement is complete is 100 + +//Question 3 (d) +for(ctr = 2; ctr < 10; ctr += 3) + //value of ctr when the statement is complete is 11 + +//Question 3 (e) +//while statement to count from 1 to 100 by 3s +#include +int main(){ + int i; + i = 1; + + while(i<= 100) +{ + printf("%d\n", i); + i += 3; +} +} +//Question 3 (f) +for (counter = 1; counter < MAXVALUES; counter++ ); +printf("\nCounter = %d", counter); +//if the for loop is required to execute multiple times, then it wont be able because of the semicolon terminating the for loop From 8c8fa9e8472cf0f58d912e038f0a56382a5da574 Mon Sep 17 00:00:00 2001 From: DavisTwine <38284972+DavisTwine@users.noreply.github.com> Date: Thu, 12 Apr 2018 09:50:41 +0000 Subject: [PATCH 4/4] QN.4 --- Question Four a.c | 7 +++++++ Question Four b.c | 50 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 Question Four a.c create mode 100644 Question Four b.c diff --git a/Question Four a.c b/Question Four a.c new file mode 100644 index 00000000..8d75e0c5 --- /dev/null +++ b/Question Four a.c @@ -0,0 +1,7 @@ +int final_array[] = {}; +void addarrays(int array1[], int array2[], int array3[], int n) { + int i = 0; + for (i = 0; i < n; i++) { + array3[i] = array1[i] + array2[i]; + } +} diff --git a/Question Four b.c b/Question Four b.c new file mode 100644 index 00000000..1ef7ab28 --- /dev/null +++ b/Question Four b.c @@ -0,0 +1,50 @@ +#include +#include + +int array3[] = {}; +int *addarrays(int array1[], int array2[], int n); + +int main(void) { + int i,n; + printf("Enter the size of the arrays: \n"); + scanf("%d",&n); + int array_one[n], array_two[n]; + + printf("Enter the first array: \n"); + + for ( i = 0; i < n; i++) { + scanf("%d", &array_one[i]); + } + + printf("Enter the second array: \n"); + + for ( i = 0; i < n; i++) { + scanf("%d", &array_two[i]); + } + + int *p; + p = addarrays(array_one, array_two, n); + printf("array one: "); + for (i=0; i < n; i++){ + printf("%d,", array_one[i]); + } + printf("\narray two: "); + for (i=0; i < n; i++){ + printf("%d,", array_two[i]); + } + printf("\narray3: "); + for (i=0; i < n; i++){ + printf("%d,", p[i]); + } + return 0; +} + +int *addarrays(int array1[], int array2[], int n) { + int i = 0; + for (i = 0; i < n; i++) { + array3[i] = array1[i] + array2[i]; + } + int *t; + t = array3; + return t; +}