(In C) This is a lab I have for homework using Jupyter Notebooks. Please help me
ID: 3876740 • Letter: #
Question
(In C) This is a lab I have for homework using Jupyter Notebooks. Please help me do this and make sure it compiles without errors, thank you.
This is the second part, after the first one is compiled and working:
Step 4: Write a Sum Function We are now going to add a sum function like in lab one, but this time we need to fill in the blank code blocks and add a function prototype to the lab1.h file. We also need to debug any of the errors in the code! Hint: There is a total of 3 errors between the "lab1.c" code and bash script for compiling. Note: You can call the sum function below the "lab1.h" function without the prototype in the Lab1.c" file because the compiler reads the prototype before calling "main" when reading the "lab1.h" header file.Explanation / Answer
1)
in labl.c to prit the sum of array values
error in function
int sum(int array[] , int arrlength)
so the error free functio will be
int sum(int array[] , int arraylength)
{
int i;
for(i=0;i<arrlength;i++)
{
int totalsum = 0;//assign the first value will be 0
for( i = 0;i < arraylength ;i++)
{
totalsum = totalsum+array[i]; // add total sum and array values
}
return totalsum;
}
2)
print the integer array value seperated by comma use this function
int printintegerarray(int array[],int arrlength)
{
int temp,temp1;
for(int i =0 ;i<=arrlength;i++)
{
if(i==0)
{
temp = array[arrlength-1];
temp1 = array[i];
array[arrlength-1] = temp1;
array[i] =temp;
}
else if(i>0)
{
for(int j = 0;j<arrlength;j++)
{
printf("%d",array[j]);
printf(",");
}
break;
}
}
use the same 1st function to add sum of array
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.