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
37 changes: 37 additions & 0 deletions Question_4a[1].txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#include <stdio.h>//preprocessor
void addarrays(int X[],int Y[],int size);//function declaration
int main()//main function
{
int A[5],B[5],C=5,i;//Array and variable declaration
printf("Enter the entries of an array A:\n");//outputs the statement in the quotes to the console
for(i=0;i<5;i++)//for loop for an array A
{
scanf("%d",&A[i]);//gets the values of array A from the keyboard
}
printf("\n");

printf("Enter the entries of an array B:\n");//outputs the statement in the quotes to the console
for(i=0;i<5;i++)//for loop for an array B
{
scanf("%d",&B[i]);//gets the values of array B from the keyboard
}
printf("\n");
addarrays(A,B,C);//Function call

return 0;
}
void addarrays(int X[],int Y[],int size)//Function header
{
int counter,C[size];//declaration of the local variables in the function definition
for(counter=0;counter<size;counter++)//for loop for the addition process
{
C[counter]=X[counter]+Y[counter];//addition process
}
printf("The values of the third array are as below\n");
for(counter=0;counter<5;counter++)//for loop for printing the output of the third array to the screen
{
printf("%d ",C[counter]);//prints the values of the third array to the screen

}
return 0;//Terminates the funtion
}
54 changes: 54 additions & 0 deletions Question_4b[1].txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@

#include <stdio.h>//preprocessor
#include<conio.h>//preprocessor
void addarrays(int X[],int Y[],int size);//function declaration
int main()//main function
{
int A[5],B[5],C=5,i;//Array and variable declaration
printf("Enter the entries of an array A:\n");//outputs the statement in the quotes to the console
for(i=0;i<5;i++)//for loop for an array A
{
scanf("%d",&A[i]);//gets the values of array A from the keyboard
}
printf("\n");//prints a new line

printf("Enter the entries of an array B:\n");//outputs the statement in the quotes to the console
for(i=0;i<5;i++)//for loop for an array B
{
scanf("%d",&B[i]);//gets the values of array B from the keyboard
}
printf("\n");
addarrays(A,B,C);//Function call
getch();

return 0;//Terminates the main function and returns zero
}
void addarrays(int X[],int Y[],int size)//Function header
{
int counter,*ptr[size],C[size];//declaration of the local variables in the function definition
printf("Values of array A:\n");
for(counter=0;counter<5;counter++)//for loop for printing the output of the third array to the screen
{
printf("%d ",X[counter]);//prints the values of the first array to the screen
}
printf("\n\n");//prints a new line

printf("Values of array B:\n");
for(counter=0;counter<5;counter++)//for loop for printing the output of the third array to the screen
{
printf("%d ",Y[counter]);//prints the values of the second array to the screen
}
printf("\n\n");//prints a new line

for(counter=0;counter<size;counter++)//for loop for the addition process
{
C[counter]=X[counter]+Y[counter];//addition process
ptr[counter]=&C[counter];//Assigns the memory address of C[counter] as a value to a pointer
}
printf("The values of the third array are as below\n");
for(counter=0;counter<5;counter++)//for loop for printing the output of the third array to the screen
{
printf("%d ",*ptr[counter]);//prints the values of the third array to the screen by dereferencing a pointer
}
return 0;//terminates the addarrays function and returns a zero
}
12 changes: 12 additions & 0 deletions Question_One[1].txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Question One
#include<stdio.h>
int x=1; /*variable is declared before the main() function */
main()
{
if(x==1)/*the if statement is not meant to be terminated and use of assignment operator instead of relational operator*/
printf("x equals 1");
else /*the if-else syntax was wrong, it cannot be if-otherwise*/
{
printf("x does not equal 1");
}

16 changes: 16 additions & 0 deletions Question_Three[1].txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Question Three
a) Long int array[50];
b) Long int array[49]= 123.456;
c) X = 99
d) ctr = 8
e) #include <stdio.h>
#include <stdlib.h>
main()
{int x=1;
while(x<=100){
printf("%d\n",x);
x+=3;

}}
f) The code under the loop is always executed once outside the for loop, because of the semicolon terminating the for loop.

7 changes: 7 additions & 0 deletions Question_Two[1].txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

Question Two
I) float do_it(char argument 1,char argument 2,char argument 3)
II) void print_a_number(int argument)
III) The function print-msg has many arguments and since it�s defined before the main() function, it should only be called at the end of the program, yet it is called twice in the program.
In addition the function declaration should have the same variable name but there is �msq� not �msg�