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
15 changes: 15 additions & 0 deletions Qtn 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#include <stdio.h>
#include <stdlib.h>
int x=1;//it had a full colon instead of a semi-colon
main()
{
if(x==1)// single equal sign(=)is not recognized as equal but instead double equal sigh(==)
{
printf("x equals 1");
}
else // otherwise is not recognized by the compilers so we use else
{
printf("x does not equal 1");
}
return 0;
}
6 changes: 6 additions & 0 deletions Qtn 2 p 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
//do_it()
//the header for above function is as below
#ifndef DO_IT_H
#define DO_IT_H
float do_it(char a, char b, char c)
#endif // DO_IT_H
8 changes: 8 additions & 0 deletions Qtn 2 p 3
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//the problems in the program of question 2 part 3 are below
-the function header was terminated and yet it
shouldn't be terminated
-the print_msg function shouldn't take any arguments
but the main function will call it with a string argument
-Another problem is that the function name in the function
declaration is print_msq() which is wrong because it sould
instead be print_msg()
6 changes: 6 additions & 0 deletions Qtn 2 p2
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
//print_a_number()
//the header for the above function is as below
#ifndef PRINT_A_NUMBER_H
#define PRINT_A_NUMBER_H
void print_a_number(int x)
#endif // PRINT_A_NUMBER_H
3 changes: 3 additions & 0 deletions Qtn 3 p 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
//the declaration that will hold 50 type long values is as below

long values[50];
3 changes: 3 additions & 0 deletions Qtn 3 p 2
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// the statement that assigns the value 123.456 to the 50th element in the array

long values[49] = 123.456;
5 changes: 5 additions & 0 deletions Qtn 3 p 3
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
for (x=0;x<100;x++)

//The value of x will be as below if the statement is complete

x=100
3 changes: 3 additions & 0 deletions Qtn 3 p 4
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
for (ctr=2;ctr<10;ctr+=3)
// The value of ctr will be as below when the statement is complete
ctr=11
14 changes: 14 additions & 0 deletions Qtn 3 p 5
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include <stdio.h>

main()
{
int count;
count=1;
while(count<=100)
{
printf("%d\n",count);
count+=3;
}
return 0;
}

5 changes: 5 additions & 0 deletions Qtn 3 p 6
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
for (counter = 1; counter < MAXVALUES; counter++ );
printf("\nCounter = %d", counter);
//the problem with the above code fragment is
the semicolon at the end of the condition is the problem because a condition
shouldn't have a semicolon at the end
8 changes: 8 additions & 0 deletions Qtn 4 p 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#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];
}
}
23 changes: 23 additions & 0 deletions Qtn 4 p2
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#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;
}
4 changes: 4 additions & 0 deletions Student details
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Niwamanya Ton Chritopher
17U/1698
BELE
217001732