diff --git a/Qtn 1 b/Qtn 1 new file mode 100644 index 00000000..8c847eda --- /dev/null +++ b/Qtn 1 @@ -0,0 +1,15 @@ +#include +#include +int x=1;//it had a full colon instead of a semi-colon +main() +{ + if(x==1)// single equal sign(=)is not recognized as equal but instead double equal sigh(==) + { + printf("x equals 1"); + } + else // otherwise is not recognized by the compilers so we use else + { + printf("x does not equal 1"); + } + return 0; +} diff --git a/Qtn 2 p 1 b/Qtn 2 p 1 new file mode 100644 index 00000000..18c863a6 --- /dev/null +++ b/Qtn 2 p 1 @@ -0,0 +1,6 @@ +//do_it() +//the header for above function is as below +#ifndef DO_IT_H +#define DO_IT_H +float do_it(char a, char b, char c) +#endif // DO_IT_H diff --git a/Qtn 2 p 3 b/Qtn 2 p 3 new file mode 100644 index 00000000..413f4c18 --- /dev/null +++ b/Qtn 2 p 3 @@ -0,0 +1,8 @@ + //the problems in the program of question 2 part 3 are below + -the function header was terminated and yet it + shouldn't be terminated + -the print_msg function shouldn't take any arguments + but the main function will call it with a string argument + -Another problem is that the function name in the function + declaration is print_msq() which is wrong because it sould + instead be print_msg() diff --git a/Qtn 2 p2 b/Qtn 2 p2 new file mode 100644 index 00000000..a436e1b3 --- /dev/null +++ b/Qtn 2 p2 @@ -0,0 +1,6 @@ +//print_a_number() +//the header for the above function is as below +#ifndef PRINT_A_NUMBER_H +#define PRINT_A_NUMBER_H +void print_a_number(int x) +#endif // PRINT_A_NUMBER_H diff --git a/Qtn 3 p 1 b/Qtn 3 p 1 new file mode 100644 index 00000000..a1c14e2e --- /dev/null +++ b/Qtn 3 p 1 @@ -0,0 +1,3 @@ + //the declaration that will hold 50 type long values is as below + + long values[50]; diff --git a/Qtn 3 p 2 b/Qtn 3 p 2 new file mode 100644 index 00000000..2738cc0c --- /dev/null +++ b/Qtn 3 p 2 @@ -0,0 +1,3 @@ +// the statement that assigns the value 123.456 to the 50th element in the array + +long values[49] = 123.456; diff --git a/Qtn 3 p 3 b/Qtn 3 p 3 new file mode 100644 index 00000000..885e33ac --- /dev/null +++ b/Qtn 3 p 3 @@ -0,0 +1,5 @@ +for (x=0;x<100;x++) + + //The value of x will be as below if the statement is complete + + x=100 diff --git a/Qtn 3 p 4 b/Qtn 3 p 4 new file mode 100644 index 00000000..aace6b62 --- /dev/null +++ b/Qtn 3 p 4 @@ -0,0 +1,3 @@ +for (ctr=2;ctr<10;ctr+=3) + // The value of ctr will be as below when the statement is complete + ctr=11 diff --git a/Qtn 3 p 5 b/Qtn 3 p 5 new file mode 100644 index 00000000..72b681b0 --- /dev/null +++ b/Qtn 3 p 5 @@ -0,0 +1,14 @@ +#include + +main() +{ + int count; + count=1; + while(count<=100) + { + printf("%d\n",count); + count+=3; + } + return 0; +} + diff --git a/Qtn 3 p 6 b/Qtn 3 p 6 new file mode 100644 index 00000000..e2f879d1 --- /dev/null +++ b/Qtn 3 p 6 @@ -0,0 +1,5 @@ + for (counter = 1; counter < MAXVALUES; counter++ ); + printf("\nCounter = %d", counter); + //the problem with the above code fragment is + the semicolon at the end of the condition is the problem because a condition + shouldn't have a semicolon at the end diff --git a/Qtn 4 p 1 b/Qtn 4 p 1 new file mode 100644 index 00000000..071e9bd5 --- /dev/null +++ b/Qtn 4 p 1 @@ -0,0 +1,8 @@ +#include +void addarrays(int array1[], int array2[], int destination_array[], int SIZE) +{ + for(int i=0;i +int *addarrays(int arraya[],int arrayb[], int SIZE); +main(){ +int arraya[] = {2,3,5,9,10}; +printf("arraya[2,3,5,9,10]\n"); +int arrayb[] = {10,23,25,17,16}; + printf("arrayb[10,23,25,17,16]\n"); + printf("arrayc "); +int *arrayc = addarrays(arraya, arrayb, 5); +int i; +for( i=0;i<5;i++) { +printf("%d,", arrayc[i]); +} +} + +int *addarrays(int arraya[], int arrayb[], int length){ +int *destination_array = malloc(length * sizeof(int)); +int i; +for( i=0;i