diff --git a/QUESTION FOUR b/QUESTION FOUR new file mode 100644 index 00000000..e937fe50 --- /dev/null +++ b/QUESTION FOUR @@ -0,0 +1,61 @@ +#include +#include + +int array1[5]={1,2,3,4,5}; +int array2[5]={5,7,8,9,3}; +int array3[5]; +int i; +void addarrays(array1,array2); +main() +{ + for (i = 0; i < 5; i++) + printf( "\narray1 [%d] = %d \tarray2 [%d] = %d ", i, + array1 [i], i, array2 [i] ); + +addarrays(array1,array2); + +return 0; +} +void addarrays(array1,array2) +{ + for (i = 0; i < 5; i++) + array3[i]=(array1 [i]+ array2[i]); + + printf("\n\nARRAY3 sums up 2 and 1"); + printf("\n.......................\n"); + + for (i = 0; i < 5; i++) + printf( "\narray3 arrays is = %d ", array3[i] ); + +return 0; +} + +part two + +#include +#include + +int array1[5]={1,2,3,4,5}; +int array2[5]={5,7,8,9,3}; +int array3[5]; +int i; +void *addarrays(array1,array2); +main() +{ + for (i = 0; i < 5; i++) + printf( "\narray1 [%d] = %d \tarray2 [%d] = %d ", i, + array1 [i], i, array2 [i] ); + +int *array3=addarrays(array1,array2); + + for (i = 0; i < 5; i++) + printf( "\narray3 arrays is = %d ", array3[i] ); +return 0; +} +void *addarrays(array1,array2) +{ + int *addarrays(array1,array2) + array3[i]=(array1 [i]+ array2[i]) + +return 0; +} diff --git a/QUESTION ONE b/QUESTION ONE new file mode 100644 index 00000000..27ffad22 --- /dev/null +++ b/QUESTION ONE @@ -0,0 +1,15 @@ +#include +/* correction to the bugs in question one*/ +int x=1; +/* its an error to use : when terminating a variable use ;*/ + +int main() +{ + if (x==1)/* an if condition is not terminated */ + printf("x is equal to 1\n"); + /*otherwise is not a C keyword instead use else */ + else + printf("x does not equal \n1"); + +return 0; +} diff --git a/QUESTION THREE b/QUESTION THREE new file mode 100644 index 00000000..6ce040cb --- /dev/null +++ b/QUESTION THREE @@ -0,0 +1,39 @@ + +// declarration for an array named data + +long data[50]; + +// this assigning a float value to an array + +float data[49]=123.456; + +/*when a for loop is run then x values will range from 0 to 99*/ +int x +for(x=0;x<100;x++) + printf("%d\n",x); + +//for is aloop hence we expect a range of values +int ctr; +for( ctr=2;ctr<10;ctr+=3) +printf("%d\n", ctr); +the values printed here will be 2,5,8 + +// symantics of a while loop + +#include + +int main() +{ + int count=1; + while(count<=100) + { + printf("%d\n",count); + count+=3; + } + return 0; +} + + the for (statement) should not be terminated + i.e for(counter=1;counter< MAXVALUES;counter++) + printf("\n counter=%d", counter); + diff --git a/QUESTION TWO b/QUESTION TWO new file mode 100644 index 00000000..aaa0165c --- /dev/null +++ b/QUESTION TWO @@ -0,0 +1,25 @@ + +/*this is a header file do_it with returning a float +with characters as list of parameters*/ +float do_it(char1,char2,char3) + +/*this function return any value*/ +void print_a_number (int x) + + +#include +// alway terminate when u call a function +void print_msg (void); +main() +{ + //the braces should be empty hence should not take any aguments +print_msg(); +return 0; +} + //the header function should be identical at any point when called +void print_msg(void) +{ + puts("this is the message to print"); + + return 0; +} diff --git a/STUDENT DETAILS b/STUDENT DETAILS new file mode 100644 index 00000000..c7a489d4 --- /dev/null +++ b/STUDENT DETAILS @@ -0,0 +1,4 @@ +EPUNE DANIEL +17/U/19796/PS +217022078 +BELE