diff --git a/QUESTION 1 b/QUESTION 1 new file mode 100644 index 00000000..ed9fafb1 --- /dev/null +++ b/QUESTION 1 @@ -0,0 +1,9 @@ +#include + int x = 1; + main(){ + if(x==1)// we don't have to terminate at the end of if statement + printf ("x equals 1"); + else // insted of using otherwise we use else + printf ("x does not equal 1"); + return 0; + } diff --git a/QUESTION 2 b/QUESTION 2 new file mode 100644 index 00000000..e597f059 --- /dev/null +++ b/QUESTION 2 @@ -0,0 +1,18 @@ + + /*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. */ diff --git a/QUESTION 3 b/QUESTION 3 new file mode 100644 index 00000000..5ae2c44d --- /dev/null +++ b/QUESTION 3 @@ -0,0 +1,21 @@ +//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. diff --git a/QUESTION 4 b/QUESTION 4 new file mode 100644 index 00000000..bd3d1b0b --- /dev/null +++ b/QUESTION 4 @@ -0,0 +1,33 @@ +//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