diff --git a/q1.c b/q1.c new file mode 100644 index 00000000..b88a9414 --- /dev/null +++ b/q1.c @@ -0,0 +1,13 @@ +#include + +int main() +{ + int x = 1; + if( x == 1){ + printf(" x equals 1" ); + } + else { + printf(" x does not equal 1"); + } + return 0; +} diff --git a/q2_problem.c b/q2_problem.c new file mode 100644 index 00000000..3332a177 --- /dev/null +++ b/q2_problem.c @@ -0,0 +1,20 @@ +//Question 2a +float do_it(char a,char b,char c); + + +//Question 2b +void print_a_number(int m); + +//Question 2c + +#include +void print_msg( void ); +main(){ + print_msg("This is a message to print");//The print_msg function does not take arguments on it. + return 0; +} +void print_msq( void ) //This is supposed to be print_msg not print_msq +{ + puts("This is a message to print"); + return 0; // This is unexpected because the return type was already specified as 'void' +} diff --git a/q3.c b/q3.c new file mode 100644 index 00000000..340d870b --- /dev/null +++ b/q3.c @@ -0,0 +1,27 @@ +//Quetion 3a +long array[50]; + +//Question 3b +long array[49] = 123.456; + +//Question 3c +for (x = 0; x < 100; x++) // x = values 0,1,2,3,4,5..........99( x values increasing from 1 t0 99) + +//Question 3d +for (ctr = 2; ctr < 10; ctr += 3) // ctr value = (2,5,8) + +//Question 3e +#include +int main() +{ +int counter, c = 1; +while ( c <= 100) { + counter = i; + c += 3; +} +return o; +} + +//Qustion 3f +for (counter = 1; counter < MAXVALUES; counter++ ); //the for loop was terminated +printf("\nCounter = %d", counter);//The function did not have braces diff --git a/q4b.c b/q4b.c new file mode 100644 index 00000000..f0895b5d --- /dev/null +++ b/q4b.c @@ -0,0 +1,50 @@ + +#include +#include + +int results[] = {}; +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_first[n], array_second[n]; + printf("Enter First array: \n"); + + for ( i = 0; i < n; i++) { + scanf("%d", &array_first[i]); + } + + printf("Enter Second array: \n"); + + for ( i = 0; i < n; i++) { + scanf("%d", &array_second[i]); + } + + int *y; + y = addarrays(array_first, array_second, n); + printf("array one: "); + for (i=0; i < n ; i++) { + printf("%d,", array_first[i]); + } + printf("\n array two: "); + for (i=0; i < n; i++){ + printf("%d,", array_second[i]); + } + printf("\nresults array: "); + for (i=0; i < n; i++){ + printf("%d,", y[i]); + } + return 0; +} + +int *addarrays(int array1[], int array2[], int n) { + int i = 0; + for (i = 0; i < n; i++) { + results[i] = array1[i] + array2[i]; + } + int *z; + z = results; + return z; +}