Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <ctype.h>
- #include <string.h>
- #include <math.h>
- int main()
- {
- int i;
- //initialize an integer/float array by putting elements in curly brackets
- //no null zero at end, that is only for character arrays
- int meatBalls[5];
- int totalBalls = 0;
- //get user input
- for(i=0; i<5; i++){
- printf("How many meatballs did you eat on day %d \n", i+1);
- scanf(" %d", &meatBalls[i]);
- }
- //calculate total amount you ate
- for(i=0; i<5; i++){
- totalBalls += meatBalls[i];
- }
- int avg = totalBalls / 5;
- printf("You ate %d total meatballs, thats an average of %d per day!", totalBalls, avg);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment