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

PROGRAMMING ASSIGNMENT #258

Open
wants to merge 2 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
3 changes: 3 additions & 0 deletions MY DETAILS
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# NAME:MUNYE BEN
# REG NO:16/U/7601/PS
# COURSE BSC ELECTRICAL ENGINEERING
31 changes: 31 additions & 0 deletions QUESTION 4.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/* solution to question four*/
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];

}
}

/* modification of the program*/
# include<stdio.h>
int*addarrays(int array1[], int array2[],int size);
int main()
{

int array1[]={1,5,3,22,6};
int array2[]={13,143,11,10,121};
int*array3=addarrays(array1,array2,5);
for(int i=0;i<5;i++){
printf("%d",array3[i])
}
}
int*addarrays(int array1[],int array2[],int len)
{
int*destination_array=malloc(len*sizeof(int));
for(inti=0;i<len;i++){
destination_array[i]=array1[i]+array2[i];
}
return destination_array;
}
12 changes: 12 additions & 0 deletions SOLUTION 1.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*solution to question 1*/
#include<stdio.h>
int x=1;
main(void)
{

if(x==1){
printf("x equals 1");}
else{
printf("x doesnt equal 1");}
return 0;
}
18 changes: 18 additions & 0 deletions SOLUTION 2.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/* Answer for a header file for do_it()*/
#ifndef DO_IT_H
#define DO_IT_H

float do_it(char a, char b, char c)

#endif//DO_IT_H
/* Answer for a header for a function print_a_number()*/
#ifndef PRINT_A_NUMBER_H
#definr PRINT_A_NUMBER_H

void print_a_number(int x)
#endif//PRINT_A_NUMBER_H

/*Answer for finding whats wrong with the program*/
The print_msg() function is not supposed to take any arguments but the
main function calls it with a string argument.

22 changes: 22 additions & 0 deletions SOLUTION 3.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/* SOLUTION TO QUESTION 3 */
long array[50]; // DECLARATION FOR AN ARRAY THAT WILL HOLD 50 TYPE LONG VALUES
long array[49]=123456;// STATEMENT THAT ASSIGNS 123.456 AS 50TH ELEMENT IN THE ABOVE ARRAY
for(x=0;x<100;x++)// THE VALUES OF X WILL BE 0 TO 99 WHEN THE "FOR" STATEMENT IS COMPLETE
for(ctr=2;ctr<10;ctr+=3)// THE VALUE OF ctr WILL BE 8 WHEN THE STATEMENT IS COMPLETED



/* WHILE STATEMENT THAT COUNTS FROM 1 TO 100 IN STEPS OF 3*/
# include <stdio.h>
main(void)
{
int count=1;
while(count<=100){
printf("%d",counter);
count+=3;
}
}

// PROBLEM WITH THE CODE
for (counter=1;counter<MAXVALUES;counter++);
printf("\nCounter=%d", counter); // THE PROBLEM IS WITH THE FOR LOOP; THE FOR LOOP IS NEVER TERMINATED WITH SEMICOLON