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; +} 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; + + } + + 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 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