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.
#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;
}
Comments
Leave a comment