Question

#include <stdio.h> extern unsigned long long sum(unsigned int *array, size_t n); int main(void) { unsigned int...

#include <stdio.h>

extern unsigned long long sum(unsigned int *array, size_t n);

int

main(void)

{

unsigned int array[] = { 1, 1, 1, 3 };

unsigned long long r = sum(array, sizeof(array) / sizeof(*array));

printf("Result is: %llu (%s)\n", r, r == 6 ? "correct" : "incorrect");

return 0;

}

Complete the code for the line that calls the sum function. Write the sum function.

Homework Answers

Answer #1
#include <stdio.h>

extern unsigned long long sum(unsigned int *array, size_t n);

int main(void) {
    unsigned int array[] = {1, 1, 1, 3};
    unsigned long long r = sum(array, sizeof(array) / sizeof(*array));
    printf("Result is: %llu (%s)\n", r, r == 6 ? "correct" : "incorrect");
    return 0;
}

unsigned long long sum(unsigned int *array, size_t n) {
    unsigned long long total = 0;
    size_t i;
    for (i = 0; i < n; ++i) {
        total += array[i];
    }
    return total;
}

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
#include<stdio.h> int main() {       /* For binary search, the array should be arranged in ascending...
#include<stdio.h> int main() {       /* For binary search, the array should be arranged in ascending or descending order */       int data[] = {1,2,3,4,5,6,7,8,9,10}; ****You might change the numbers for your program also       /* 'min' use for starting location of the array, 'max' use for end location of the array and 'mid' use for middle location of the array */       int min = 0, max = 10, search, mid = (max + min) / 2;       printf("Enter...
could someone please explain this code and the output to me? #include <stdio.h> #include <unistd.h> int...
could someone please explain this code and the output to me? #include <stdio.h> #include <unistd.h> int main(void) { printf("one\n"); fork(); printf("two\n"); return 0; }
create case 4 #include <stdio.h> int main(void) { int counter; int choice; FILE *fp; char item[100];...
create case 4 #include <stdio.h> int main(void) { int counter; int choice; FILE *fp; char item[100]; while(1) { printf("Welcome to my shopping list\n\n"); printf("Main Menu:\n"); printf("1. Add to list\n"); printf("2. Print List\n"); printf("3. Delete List\n"); printf("4. Remove an item from the List\n"); printf("5. Exit\n\n"); scanf("%i", &choice); switch(choice) { case 1: //add to list //get the input from the user printf("Enter item: "); scanf("%s", item); //open the file fp = fopen("list.txt","a"); //write to the file fprintf(fp, "\n%s", item); //close the file...
#include <stdio.h> int main( void ) {     double height, weight, bmi;     int bmievalcode;    ...
#include <stdio.h> int main( void ) {     double height, weight, bmi;     int bmievalcode;     while( 1 )     {         /* --> add code to input weight and height between here */         scanf("%lf %lf\n" , &weight &height)         bmi = weight * 703 / (height * height);         /* <-- and here */         /* --> add code to calculate bmi and bmievalcode between here */         if (bmi <= 00.0){             bmievalcode = -1;         else...
What is output? #include <stdio.h> void CheckValue(int* pointVar1, int* pointVar2) {       if (pointVar1 == NULL...
What is output? #include <stdio.h> void CheckValue(int* pointVar1, int* pointVar2) {       if (pointVar1 == NULL && pointVar2 == NULL) {       printf("Pointer is null\n");    }    else if (*pointVar2 > *pointVar1) {       printf("%p\n", *pointVar2);    }    else if (*pointVar1 > *pointVar2) {       printf("%p\n", *pointVar1);    } } int main() {    int num1 = 5;    int num2 = 9;       CheckValue(&num1, &num2);           return 0; } a. 0 b. 5 c. 9 d. Pointer is null e....
#include <stdio.h> #include <stdlib.h> int main () { int k; int aux; int size = 8;...
#include <stdio.h> #include <stdlib.h> int main () { int k; int aux; int size = 8; int x[8] = {2, 3, 5, 7, 11, 13, 17, 19}; scanf("%d",&k); aux = x[k]; for (int i = k; i < size - 1; i++) x[i] = x[ i + 1]; x[ size - 1] = aux;   for (int i = 0; i < size; i++) printf("%d ", x[i]); } change this program to Write a program to remove an element from an...
#include int main() { const size_t num_lists = 3; float* a[num_lists]; size_t sizes[num_lists] = {6, 6,...
#include int main() { const size_t num_lists = 3; float* a[num_lists]; size_t sizes[num_lists] = {6, 6, 6}; for(int k=0; k < 3; k++) { a[k] = (float*)malloc(sizes[k] * sizeof(float)); } // ... } Now consider the array a. Match each expression to the data type of the expression's value: (float, float*,float**,float*[3]) a    a[2] a[2][1] &a[2][1] &a[2] *a
A program is already given to you.  There are five problems in this skeleton version of the...
A program is already given to you.  There are five problems in this skeleton version of the program, each is 10 points. All you got to do is complete the missing code in each function. What the function does is clearly stated in the name of the function.   // ASSIGNMENT ON FUNCTIONS #include <stdio.h> // Problem 1: Compile with gcc func_assignment.c -Wall // There are some warnings because there is a mismatch between // data type passed and defined. // Find...
Translate the following C program to Pep/9 assembly language. #include <stdio.h.> int main() { int numitms,j,data,sum;...
Translate the following C program to Pep/9 assembly language. #include <stdio.h.> int main() { int numitms,j,data,sum; scanf("%d", &numitms); sum=0; for (j=1;j<=numitms;j++) { scanf("%d", &data); sum+=data; } printf("sum: %d\n",sum); return0; } Please test the answer using Pep/9. Thank you so much!
Construct a flowchart based on this code and write its equivalent algorithms. #include <stdio.h> int main()...
Construct a flowchart based on this code and write its equivalent algorithms. #include <stdio.h> int main() { int x,y; float result; char ch; //to store operator choice printf("Enter first number: "); scanf("%d",&x); printf("Enter second number: "); scanf("%d",&y); printf("Choose operation to perform (+,-,*,/): "); scanf(" %c",&ch); result=0; switch(ch) { case '+': result=x+y; break; case '-': result=x-y; break; case '*': result=x*y; break; case '/': result=(float)x/(float)y; break; case '%': result=x%y; break; default: printf("Invalid operation.\n"); } printf("Result: %d %c %d = %.2f\n",x,ch,y,result); // Directly...