Answer to Question #271101 in C for jose

Question #271101

Write a C program that would prompt a user to enter weight of five people and store the values in an array. The program the computes and outputs the total weight.


1
Expert's answer
2021-11-24T13:47:26-0500
#include <stdio.h>

int main() {
  printf("Enter weight of 5 people\n");
  int weight[5];
  int total = 0;
  for (int i = 1; i <= 5; i++) {
    printf("Weight %d: ", i);
    scanf("%d", weight + i - 1);
    total += weight[i - 1];
  }
  printf("Total: %d\n", total);
  return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS