Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RWEGO NDAHIRO DAVID Reg No: 16/X/2364/PS #262

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
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
12 changes: 12 additions & 0 deletions QUESTION 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/* Rwego Ndahiro David
reg no: 16/X/2364/PS*/
#include <stdio.h>
int x = 1;
main()
{
if(x==1)
printf ("x equals 1");
else
printf ("x does not equal 1");
return 0;
}
20 changes: 20 additions & 0 deletions QUESTION 2
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

/*Rwego Ndahiro David
Reg No: 16/X/2364/PS
ANSWER OF QUESTION 2:
I) (do_it.h)*/

#ifndef DO_IT_H
#define DO_IT_H
float do_it(char x, char y, char z);
#endif // DO_IT_H

//II) (print_a_number.h)
#ifndef PRINT_A_NUMBER_H
#define PRINT_A_NUMBER_H
void print_a_number(int a);
#endif // PRINT_A_NUMBER_H

/*iii)

The print_msg() function shouldn’t take any arguments because the main function calls already have one. */
28 changes: 28 additions & 0 deletions QUESTION 3
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Rwego Ndahiro David
// Reg No: 16/X/2364/PS
//Answers of question 3:
//i) long values[50];

//ii) long values[49] = 123.456;

//iii) x is equal to 99 when the statement is complete

//iv) The value of ctr is 8 when the statement is complete




//v)
#include <stdio.h>
main(){
int x = 1;
while(x <= 100){
//vi)
printf("The value of x : %d\n ", x);
x += 3;
}
}
//Comment: The X will be counted from 1 to 100 by adding 3

//vii) We don’t have to put the semicolon to terminate the for loop and the statements for a for loop should be enclosed.

38 changes: 38 additions & 0 deletions QUESTION 4
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/* Rwego Ndahiro David
Reg No: 16/X/2364/PS*/
//ANSWERS:
//i)
void addarrays(int array1[], int array2[], int summation_array[], int SIZE)
{
for(int i=0;i<SIZE;i++)
{
//ii)
summation_array[i] = array1[i] + array2[i];
}
}

//iii)
#include <stdio.h>
int *addarrays(int array1[], int array2[], int SIZE);

main(){
//iv)
int array1[] = {1,2,3,4,5};

int array2[] = {6,7,8,9,10};

int *array3 = addarrays(array1, array2, 5);

for(int i=0;i<5;i++) {
//v)
printf("%d \n", array3[i]);
}
}
int *addarrays(int array1[], int array2[], int length){
int *destination_array = malloc(length * sizeof(int));
for(int i=0;i<length;i++){
//vi)
destination_array[i] = array1[i] + array2[i];
}
return destination_array;
}