Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions QUESTION FOUR
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include<stdio.h>
void addarrays(int array1[], int array2[], int destination_array[], int SIZE)
{
for(int i=0;i<SIZE;i++)
{
destination_array[i] = array1[i] + array2[i];
}
}


#include <stdio.h>
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<length;i++){
destination_array[i] = arraya[i] + arrayb[i];
}
return destination_array;
}
17 changes: 17 additions & 0 deletions QUESTION ONE
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include <stdio.h>
#include <stdlib.h>
main()
{
int x = 1;

if(x==1)
{
printf("x equals 1");
}
else
{
printf("x does not equal 1");
}
return 0;
}

24 changes: 24 additions & 0 deletions QUESTION THREE
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*declaration of an array that will hold type long values*/
long people[50];

/* A statement that assigns a value of 123.456 to the 50th element in the array*/
long people[49]=123456;

/* what is the value of x whenthe following statement is complete*/
for(x=0;x<100,x++) /* The final value of x is 100 */

/* What is the value of ctr when the following statment is complete */
for(ctr=2;ctr<10;ctr+=3) /* The final value of ctr is 11 */

/* A while statement to count from 1 to 100 in intervals of 3s */
int x=1;
while(x<=100)
{
printf("%d",x);
x+=3;
}

/* What is wrong with the folowing code fragment(MAXVALUES is the problem!)*/
for(counter=1;counter<MAXVALUES;counter++); /* The problem is that the for loop has been terminated here by the semi colon(;) thus the program won't run since the code under the loop is only executed only once */
printf("\ncounter=%d",counter);

7 changes: 7 additions & 0 deletions QUESTION TWO
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
do_it()
//the header for above function is as below
float do_it(char a,char b,char c)

print_a_number()
//the header for the above function is as below
void print_a_number(int x)