From ea835494a43d02b979044e6ce54fcb40eb540a7d Mon Sep 17 00:00:00 2001 From: AlvinMM <38310251+AlvinMM@users.noreply.github.com> Date: Thu, 12 Apr 2018 11:56:58 +0300 Subject: [PATCH 1/5] Add files via upload --- Question_One[1].txt | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 Question_One[1].txt diff --git a/Question_One[1].txt b/Question_One[1].txt new file mode 100644 index 00000000..85f4450c --- /dev/null +++ b/Question_One[1].txt @@ -0,0 +1,12 @@ +Question One +#include +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"); + } + From 92a0b5325ef0fe244d314a1577074510aee4664e Mon Sep 17 00:00:00 2001 From: AlvinMM <38310251+AlvinMM@users.noreply.github.com> Date: Thu, 12 Apr 2018 11:57:19 +0300 Subject: [PATCH 2/5] Add files via upload --- Question_Two[1].txt | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 Question_Two[1].txt diff --git a/Question_Two[1].txt b/Question_Two[1].txt new file mode 100644 index 00000000..539db18e --- /dev/null +++ b/Question_Two[1].txt @@ -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” + From 363457623bef0bb5bdcc01155e8bd0b851e53d37 Mon Sep 17 00:00:00 2001 From: AlvinMM <38310251+AlvinMM@users.noreply.github.com> Date: Thu, 12 Apr 2018 11:57:45 +0300 Subject: [PATCH 3/5] Add files via upload --- Question_Three[1].txt | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 Question_Three[1].txt diff --git a/Question_Three[1].txt b/Question_Three[1].txt new file mode 100644 index 00000000..2e2808e6 --- /dev/null +++ b/Question_Three[1].txt @@ -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 +#include +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. + From 8e466f1b135c866f6ec2b279d2e072a33747b518 Mon Sep 17 00:00:00 2001 From: AlvinMM <38310251+AlvinMM@users.noreply.github.com> Date: Thu, 12 Apr 2018 11:58:12 +0300 Subject: [PATCH 4/5] Add files via upload --- Question_4a[1].txt | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 Question_4a[1].txt diff --git a/Question_4a[1].txt b/Question_4a[1].txt new file mode 100644 index 00000000..d91ed9b5 --- /dev/null +++ b/Question_4a[1].txt @@ -0,0 +1,37 @@ +#include //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 Date: Thu, 12 Apr 2018 11:58:33 +0300 Subject: [PATCH 5/5] Add files via upload --- Question_4b[1].txt | 54 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 Question_4b[1].txt diff --git a/Question_4b[1].txt b/Question_4b[1].txt new file mode 100644 index 00000000..3c2c0905 --- /dev/null +++ b/Question_4b[1].txt @@ -0,0 +1,54 @@ + +#include //preprocessor +#include//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