diff --git a/4a.txt b/4a.txt new file mode 100644 index 0000000..d91ed9b --- /dev/null +++ b/4a.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//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 +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"); + } + diff --git a/Question_Three[1].txt b/Question_Three[1].txt new file mode 100644 index 0000000..2e2808e --- /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. + diff --git a/Question_Two[1].txt b/Question_Two[1].txt new file mode 100644 index 0000000..539db18 --- /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” +